Skip to content

Commit da26175

Browse files
committed
✅: pyright
Signed-off-by: nstarman <nstarman@users.noreply.github.com>
1 parent e08019c commit da26175

File tree

6 files changed

+400
-369
lines changed

6 files changed

+400
-369
lines changed

.github/workflows/ci.yml

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,36 +98,41 @@ jobs:
9898
echo "major=$major" >> $GITHUB_OUTPUT
9999
echo "minor=$minor" >> $GITHUB_OUTPUT
100100
101-
- name: install deps
102-
run: |
103-
uv sync --no-editable --group=mypy
104-
uv pip install numpy==${{ matrix.numpy-version }}
105-
106-
# NOTE: `uv run --with=...` will be ignored by mypy (and `--isolated` does not help)
107-
- name: mypy
101+
- name: collect test files
102+
id: collect-files
108103
run: |
109104
major="${{ steps.numpy-version.outputs.major }}"
110105
minor="${{ steps.numpy-version.outputs.minor }}"
111106
112-
# Directory containing versioned test files
113107
prefix="tests/integration"
114108
files=""
115109
116-
# Find all test files matching the current major version
117-
for path in $(find "$prefix" -name "test_numpy${major}p*.pyi"); do
118-
# Extract file name
110+
while IFS= read -r -d '' path; do
119111
fname=$(basename "$path")
120-
# Parse the minor version from the filename
121112
fminor=$(echo "$fname" | sed -E "s/test_numpy${major}p([0-9]+)\.pyi/\1/")
122-
# Include files where minor version ≤ NumPy's minor
123113
if [ "$fminor" -le "$minor" ]; then
124114
files="$files $path"
125115
fi
126-
done
116+
done < <(find "$prefix" -name "test_numpy${major}p*.pyi" -print0)
127117
118+
files="${files# }"
119+
echo "files=$files" >> "$GITHUB_OUTPUT"
120+
121+
# NOTE: `uv run --with=...` will be ignored by mypy (and `--isolated` does not help)
122+
- name: mypy
123+
run: |
124+
uv sync --no-editable --group=mypy
125+
uv pip install numpy==${{ matrix.numpy-version }}
128126
uv run --no-sync --active \
129127
mypy --tb --no-incremental --cache-dir=/dev/null \
130-
$files
128+
${{ steps.collect-files.outputs.files }}
129+
130+
- name: pyright
131+
run: |
132+
uv sync --no-editable --group=pyright
133+
uv pip install numpy==${{ matrix.numpy-version }}
134+
uv run --no-sync --active \
135+
pyright ${{ steps.collect-files.outputs.files }}
131136
132137
# TODO: (based)pyright
133138

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ test_runtime = [
6262
test_numpy = [
6363
"numpy>=1.25",
6464
]
65+
pyright = [
66+
"pyright>=1.1.403",
67+
]
6568

6669
[tool.hatch]
6770
version.source = "vcs"

tests/integration/test_numpy1p0.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ _: xpt.HasArrayNamespace[ModuleType] = nparr_i32
2222
_: xpt.HasArrayNamespace[ModuleType] = nparr_f32
2323

2424
# Check `__array_namespace__` method
25-
a_ns: xpt.HasArrayNamespace[ModuleType] = nparr
26-
ns: ModuleType = a_ns.__array_namespace__()
25+
has_ns: xpt.HasArrayNamespace[ModuleType] = nparr
26+
ns: ModuleType = has_ns.__array_namespace__()
2727

2828
# Incorrect values are caught when using `__array_namespace__` and
2929
# backpropagated to the type of `a_ns`
@@ -43,7 +43,7 @@ _: xpt.HasDType[dtype[Any]] = nparr_f32
4343
# `xpt.Array`
4444

4545
# Check NamespaceT_co assignment
46-
a_ns: xpt.Array[Any, ModuleType] = nparr
46+
_: xpt.Array[Any, ModuleType] = nparr
4747

4848
# Check DTypeT_co assignment
4949
# Note that `np.array_api` uses dtype objects, not dtype classes, so we can't

tests/integration/test_numpy2p0.pyi

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,32 @@ nparr_b: npt.NDArray[np.bool_]
2222
# `xpt.HasArrayNamespace`
2323

2424
# Check assignment
25-
_: xpt.HasArrayNamespace[ModuleType] = nparr
26-
_: xpt.HasArrayNamespace[ModuleType] = nparr_i32
27-
_: xpt.HasArrayNamespace[ModuleType] = nparr_f32
28-
_: xpt.HasArrayNamespace[ModuleType] = nparr_b
25+
_001: xpt.HasArrayNamespace[ModuleType] = nparr
26+
_002: xpt.HasArrayNamespace[ModuleType] = nparr_i32
27+
_003: xpt.HasArrayNamespace[ModuleType] = nparr_f32
28+
_004: xpt.HasArrayNamespace[ModuleType] = nparr_b
2929

3030
# Check `__array_namespace__` method
3131
a_ns: xpt.HasArrayNamespace[ModuleType] = nparr
3232
ns: ModuleType = a_ns.__array_namespace__()
3333

34-
# Incorrect values are caught when using `__array_namespace__` and
35-
# backpropagated to the type of `a_ns`
36-
_: xpt.HasArrayNamespace[dict[str, int]] = nparr # not caught
37-
3834
# =========================================================
3935
# `xpt.HasDType`
4036

4137
# Check DTypeT_co assignment
42-
_: xpt.HasDType[Any] = nparr
43-
_: xpt.HasDType[np.dtype[I32]] = nparr_i32
44-
_: xpt.HasDType[np.dtype[F32]] = nparr_f32
45-
_: xpt.HasDType[np.dtype[np.bool_]] = nparr_b
38+
_005: xpt.HasDType[Any] = nparr
39+
_006: xpt.HasDType[np.dtype[I32]] = nparr_i32
40+
_007: xpt.HasDType[np.dtype[F32]] = nparr_f32
41+
_008: xpt.HasDType[np.dtype[np.bool_]] = nparr_b
4642

4743
# =========================================================
4844
# `xpt.Array`
4945

5046
# Check NamespaceT_co assignment
51-
a_ns: xpt.Array[Any, ModuleType] = nparr
47+
x_ns: xpt.Array[Any, ModuleType] = nparr
5248

5349
# Check DTypeT_co assignment
54-
_: xpt.Array[Any] = nparr
55-
_: xpt.Array[np.dtype[I32]] = nparr_i32
56-
_: xpt.Array[np.dtype[F32]] = nparr_f32
57-
_: xpt.Array[np.dtype[np.bool_]] = nparr_b
50+
_009: xpt.Array[Any] = nparr
51+
_010: xpt.Array[np.dtype[I32]] = nparr_i32
52+
_011: xpt.Array[np.dtype[F32]] = nparr_f32
53+
_012: xpt.Array[np.dtype[np.bool_]] = nparr_b

tests/integration/test_numpy2p2.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ from test_numpy2p0 import nparr
22

33
import array_api_typing as xpt
44

5-
_: xpt.HasArrayNamespace[dict[str, int]] = nparr # type: ignore[assignment]
5+
# Incorrect values are caught when using `__array_namespace__` and
6+
# backpropagated to the type of `a_ns`
7+
a_ns: xpt.HasArrayNamespace[dict[str, int]] = nparr # type: ignore[assignment]

0 commit comments

Comments
 (0)