Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,38 +98,48 @@ jobs:
echo "major=$major" >> $GITHUB_OUTPUT
echo "minor=$minor" >> $GITHUB_OUTPUT

- name: install deps
run: |
uv sync --no-editable --group=mypy
uv pip install numpy==${{ matrix.numpy-version }}

# NOTE: `uv run --with=...` will be ignored by mypy (and `--isolated` does not help)
- name: mypy
- name: collect test files
id: collect-files
run: |
major="${{ steps.numpy-version.outputs.major }}"
minor="${{ steps.numpy-version.outputs.minor }}"

# Directory containing versioned test files
prefix="tests/integration"
files=""

# Find all test files matching the current major version
for path in $(find "$prefix" -name "test_numpy${major}p*.pyi"); do
# Extract file name
while IFS= read -r -d '' path; do
fname=$(basename "$path")
# Parse the minor version from the filename
fminor=$(echo "$fname" | sed -E "s/test_numpy${major}p([0-9]+)\.pyi/\1/")
# Include files where minor version ≤ NumPy's minor
if [ "$fminor" -le "$minor" ]; then
files="$files $path"
fi
done
done < <(find "$prefix" -name "test_numpy${major}p*.pyi" -print0)

files="${files# }"
echo "files=$files" >> "$GITHUB_OUTPUT"

# NOTE: `uv run --with=...` will be ignored by mypy (and `--isolated` does not help)
- name: mypy
run: |
uv sync --no-editable --group=mypy
uv pip install numpy==${{ matrix.numpy-version }}
uv run --no-sync --active \
mypy --tb --no-incremental --cache-dir=/dev/null \
$files
${{ steps.collect-files.outputs.files }}

# TODO: (based)pyright
- name: pyright
run: |
uv sync --no-editable --group=pyright
uv pip install numpy==${{ matrix.numpy-version }}
uv run --no-sync --active \
pyright ${{ steps.collect-files.outputs.files }}

- name: basedpyright
run: |
uv sync --no-editable --group=basedpyright
uv pip install numpy==${{ matrix.numpy-version }}
uv run --no-sync --active \
basedpyright ${{ steps.collect-files.outputs.files }}

# TODO: integration tests for array-api-strict
# TODO: integration tests for 3rd party libs such as cupy, pytorch, tensorflow, dask, etc.
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ test_runtime = [
test_numpy = [
"numpy>=1.25",
]
pyright = [
"pyright>=1.1.403",
]
basedpyright = [
"basedpyright>=1.31.3",
]

[tool.hatch]
version.source = "vcs"
Expand Down Expand Up @@ -89,6 +95,9 @@ local_partial_types = true
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
warn_unreachable = true

[tool.pyright]
typeCheckingMode = "strict"

[tool.pytest.ini_options]
addopts = [
"--showlocals",
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_numpy1p0.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ _: xpt.HasArrayNamespace[ModuleType] = nparr_i32
_: xpt.HasArrayNamespace[ModuleType] = nparr_f32

# Check `__array_namespace__` method
a_ns: xpt.HasArrayNamespace[ModuleType] = nparr
ns: ModuleType = a_ns.__array_namespace__()
has_ns: xpt.HasArrayNamespace[ModuleType] = nparr
ns: ModuleType = has_ns.__array_namespace__()

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

# Check NamespaceT_co assignment
a_ns: xpt.Array[Any, ModuleType] = nparr
_: xpt.Array[Any, ModuleType] = nparr

# Check DTypeT_co assignment
# Note that `np.array_api` uses dtype objects, not dtype classes, so we can't
Expand Down
30 changes: 13 additions & 17 deletions tests/integration/test_numpy2p0.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,32 @@ nparr_b: npt.NDArray[np.bool_]
# `xpt.HasArrayNamespace`

# Check assignment
_: xpt.HasArrayNamespace[ModuleType] = nparr
_: xpt.HasArrayNamespace[ModuleType] = nparr_i32
_: xpt.HasArrayNamespace[ModuleType] = nparr_f32
_: xpt.HasArrayNamespace[ModuleType] = nparr_b
_001: xpt.HasArrayNamespace[ModuleType] = nparr
_002: xpt.HasArrayNamespace[ModuleType] = nparr_i32
_003: xpt.HasArrayNamespace[ModuleType] = nparr_f32
_004: xpt.HasArrayNamespace[ModuleType] = nparr_b

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

# Incorrect values are caught when using `__array_namespace__` and
# backpropagated to the type of `a_ns`
_: xpt.HasArrayNamespace[dict[str, int]] = nparr # not caught

# =========================================================
# `xpt.HasDType`

# Check DTypeT_co assignment
_: xpt.HasDType[Any] = nparr
_: xpt.HasDType[np.dtype[I32]] = nparr_i32
_: xpt.HasDType[np.dtype[F32]] = nparr_f32
_: xpt.HasDType[np.dtype[np.bool_]] = nparr_b
_005: xpt.HasDType[Any] = nparr
_006: xpt.HasDType[np.dtype[I32]] = nparr_i32
_007: xpt.HasDType[np.dtype[F32]] = nparr_f32
_008: xpt.HasDType[np.dtype[np.bool_]] = nparr_b

# =========================================================
# `xpt.Array`

# Check NamespaceT_co assignment
a_ns: xpt.Array[Any, ModuleType] = nparr
x_ns: xpt.Array[Any, ModuleType] = nparr

# Check DTypeT_co assignment
_: xpt.Array[Any] = nparr
_: xpt.Array[np.dtype[I32]] = nparr_i32
_: xpt.Array[np.dtype[F32]] = nparr_f32
_: xpt.Array[np.dtype[np.bool_]] = nparr_b
_009: xpt.Array[Any] = nparr
_010: xpt.Array[np.dtype[I32]] = nparr_i32
_011: xpt.Array[np.dtype[F32]] = nparr_f32
_012: xpt.Array[np.dtype[np.bool_]] = nparr_b
4 changes: 3 additions & 1 deletion tests/integration/test_numpy2p2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ from test_numpy2p0 import nparr

import array_api_typing as xpt

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