Skip to content

Commit 9b42f87

Browse files
committed
✅: pyright
Signed-off-by: nstarman <[email protected]>
1 parent e08019c commit 9b42f87

File tree

5 files changed

+385
-352
lines changed

5 files changed

+385
-352
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ _: xpt.HasDType[np.dtype[np.bool_]] = nparr_b
4848
# `xpt.Array`
4949

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

5353
# Check DTypeT_co assignment
5454
_: xpt.Array[Any] = nparr

0 commit comments

Comments
 (0)