Skip to content

Commit 1a33939

Browse files
authored
TYP: adopt based{mypy, pyright} (#37)
* TYP: adopt based{mypy, pyright} * fix link in comments * DEV: update lockfile * address review comments * update lockfile * ignore missing xp-strict stubs * update docs
1 parent c1d0e20 commit 1a33939

File tree

9 files changed

+292
-298
lines changed

9 files changed

+292
-298
lines changed

.github/workflows/ci.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ jobs:
3434
with:
3535
pixi-version: v0.37.0
3636
cache: true
37-
- name: Run Pylint & Mypy
37+
- name: Run Pylint, Mypy & Pyright
3838
run: |
3939
pixi run -e lint pylint
4040
pixi run -e lint mypy
41+
pixi run -e lint pyright
4142
4243
checks:
4344
name: Check ${{ matrix.environment }}

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030

3131
Extra array functions built on top of the array API standard.
3232

33+
Used by:
34+
35+
- https://github.com/scipy/scipy
36+
- ...
37+
3338
## Contributors
3439

3540
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->

codecov.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
comment: false
2+
ignore:
3+
- "src/array_api_extra/_typing"

docs/contributing.md

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ pixi run ipython
7575
pixi run pre-commit
7676
pixi run pylint
7777
pixi run mypy
78+
pixi run pyright
7879
```
7980

8081
Alternative environments are available with a subset of the dependencies and

pixi.lock

+246-282
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+22-2
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,23 @@ array-api-extra = { path = ".", editable = true }
7070

7171
[tool.pixi.feature.lint.dependencies]
7272
pre-commit = "*"
73-
mypy = "*"
7473
pylint = "*"
7574
# import dependencies for mypy:
7675
array-api-strict = "*"
7776
numpy = "*"
7877
pytest = "*"
7978

79+
[tool.pixi.feature.lint.pypi-dependencies]
80+
basedmypy = { version = "*", extras = ["faster-cache"] }
81+
basedpyright = "*"
82+
8083
[tool.pixi.feature.lint.tasks]
8184
pre-commit-install = { cmd = "pre-commit install" }
8285
pre-commit = { cmd = "pre-commit run -v --all-files --show-diff-on-failure" }
8386
mypy = { cmd = "mypy", cwd = "." }
8487
pylint = { cmd = ["pylint", "array_api_extra"], cwd = "src" }
85-
lint = { depends-on = ["pre-commit", "pylint", "mypy"] }
88+
pyright = { cmd = "basedpyright", cwd = "." }
89+
lint = { depends-on = ["pre-commit", "pylint", "mypy", "pyright"] }
8690

8791
[tool.pixi.feature.tests.dependencies]
8892
pytest = ">=6"
@@ -165,13 +169,29 @@ enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
165169
warn_unreachable = true
166170
disallow_untyped_defs = false
167171
disallow_incomplete_defs = false
172+
# data-apis/array-api#589
173+
disallow_any_expr = false
168174

169175
[[tool.mypy.overrides]]
170176
module = "array_api_extra.*"
171177
disallow_untyped_defs = true
172178
disallow_incomplete_defs = true
173179

174180

181+
# pyright
182+
183+
[tool.basedpyright]
184+
include = ["src", "tests"]
185+
pythonVersion = "3.10"
186+
pythonPlatform = "All"
187+
typeCheckingMode = "all"
188+
189+
# data-apis/array-api#589
190+
reportAny = false
191+
reportExplicitAny = false
192+
reportUnknownMemberType = false
193+
194+
175195
# Ruff
176196

177197
[tool.ruff]

src/array_api_extra/_funcs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from __future__ import annotations
22

3+
import typing
34
import warnings
4-
from typing import TYPE_CHECKING
55

6-
if TYPE_CHECKING:
6+
if typing.TYPE_CHECKING:
77
from ._typing import Array, ModuleType
88

99
__all__ = ["atleast_nd", "cov", "create_diagonal", "expand_dims", "kron", "sinc"]

src/array_api_extra/_typing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from types import ModuleType
44
from typing import Any
55

6-
Array = Any # To be changed to a Protocol later (see array-api#589)
6+
# To be changed to a Protocol later (see data-apis/array-api#589)
7+
Array = Any # type: ignore[no-any-explicit]
78

89
__all__ = ["Array", "ModuleType"]

tests/test_funcs.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
from __future__ import annotations
22

33
import contextlib
4+
import typing
45
import warnings
5-
from typing import TYPE_CHECKING, Any
66

77
# array-api-strict#6
8-
import array_api_strict as xp # type: ignore[import-untyped]
8+
import array_api_strict as xp # type: ignore[import-untyped] # pyright: ignore[reportMissingTypeStubs]
99
import numpy as np
1010
import pytest
1111
from numpy.testing import assert_allclose, assert_array_equal, assert_equal
1212

1313
from array_api_extra import atleast_nd, cov, create_diagonal, expand_dims, kron, sinc
1414

15-
if TYPE_CHECKING:
16-
Array = Any # To be changed to a Protocol later (see array-api#589)
15+
if typing.TYPE_CHECKING:
16+
from array_api_extra._typing import Array
1717

1818

1919
class TestAtLeastND:
@@ -131,7 +131,7 @@ def test_1d(self):
131131

132132
@pytest.mark.parametrize("n", range(1, 10))
133133
@pytest.mark.parametrize("offset", range(1, 10))
134-
def test_create_diagonal(self, n, offset):
134+
def test_create_diagonal(self, n: int, offset: int):
135135
# from scipy._lib tests
136136
rng = np.random.default_rng(2347823)
137137
one = xp.asarray(1.0)
@@ -180,9 +180,9 @@ def test_basic(self):
180180
assert_array_equal(kron(a, b, xp=xp), k)
181181

182182
def test_kron_smoke(self):
183-
a = xp.ones([3, 3])
184-
b = xp.ones([3, 3])
185-
k = xp.ones([9, 9])
183+
a = xp.ones((3, 3))
184+
b = xp.ones((3, 3))
185+
k = xp.ones((9, 9))
186186

187187
assert_array_equal(kron(a, b, xp=xp), k)
188188

@@ -197,7 +197,7 @@ def test_kron_smoke(self):
197197
((2, 0, 0, 2), (2, 0, 2)),
198198
],
199199
)
200-
def test_kron_shape(self, shape_a, shape_b):
200+
def test_kron_shape(self, shape_a: tuple[int, ...], shape_b: tuple[int, ...]):
201201
a = xp.ones(shape_a)
202202
b = xp.ones(shape_b)
203203
normalised_shape_a = xp.asarray(
@@ -271,7 +271,7 @@ def test_simple(self):
271271
assert_allclose(w, xp.flip(w, axis=0))
272272

273273
@pytest.mark.parametrize("x", [0, 1 + 3j])
274-
def test_dtype(self, x):
274+
def test_dtype(self, x: int | complex):
275275
with pytest.raises(ValueError, match="real floating data type"):
276276
sinc(xp.asarray(x), xp=xp)
277277

0 commit comments

Comments
 (0)