Skip to content

Commit 72190c1

Browse files
committed
🐴 workaround a mypy/stubtest issue with sys.version_info
1 parent 77797f4 commit 72190c1

File tree

5 files changed

+34
-31
lines changed

5 files changed

+34
-31
lines changed

.mypyignore

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
# intentional type-check-only deviations from runtime
12
numpy\.__numtype__
2-
numpy\.polynomial\._polytypes
33
numpy\._typing.*
4-
numpy\.typing\.mypy_plugin
4+
numpy\.polynomial\._polytypes
5+
56

67
# internal testing code
78
numpy\.conftest
@@ -25,11 +26,16 @@ numpy\.matlib\.__all__
2526
# requires numpy/_core/code_generators to be on the PYTHONPATH when running stubtest
2627
numpy\._core\.cversions
2728

29+
# mypy plugin
30+
numpy\.typing\.mypy_plugin
31+
32+
2833
# workaround mypy's lack of Python 3.13 support for `NamedTuple` types (mypy <= 1.15.0)
29-
numpy\._core\.overrides\.ArgSpec\.__replace__
30-
numpy\._utils\._pep440\._Version\.__replace__
31-
numpy\.lib\._arraysetops_impl\.Unique(All|Counts|Inverse)Result\.__replace__
32-
numpy\.linalg\._linalg\.(Eig|Eigh|QR|SVD|Slogdet)Result\.__replace__
34+
numpy(\.\w+)+\.__replace__
3335

3436
# workaround for https://github.com/python/mypy/issues/15302#issuecomment-2701979355
3537
numpy\.testing(\._private\.utils)?\.check_support_sve
38+
39+
# workaround for stubtest ignoring `if sys.version_info` blocks in `_typeshed` when
40+
# `python_version`
41+
numpy\.testing\.TestCase\.[_a-zA-Z]+

.mypyignore-todo

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,4 @@ numpy.polynomial.polynomial.polyvander
231231
numpy.polynomial.polynomial.polyvander2d
232232
numpy.polynomial.polynomial.polyvander3d
233233

234-
numpy.testing.TestCase.__init_subclass__
235-
numpy.testing.TestCase._addSkip
236-
numpy.testing.TestCase.assertDictContainsSubset
237-
numpy.testing.TestCase.enter(Class)?Context
238-
239234
numpy.typing.NBitBase

src/numpy-stubs/testing/_private/utils.pyi

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,12 @@ else:
170170

171171
#
172172
def print_assert_equal(test_string: str, actual: object, desired: object) -> None: ...
173+
174+
#
173175
def assert_(val: object, msg: str | Callable[[], str] = "") -> None: ...
174176
def assert_equal(
175-
actual: ArrayLike,
176-
desired: ArrayLike,
177+
actual: object,
178+
desired: object,
177179
err_msg: str = "",
178180
verbose: bool = True,
179181
*,
@@ -216,8 +218,8 @@ def assert_array_compare(
216218

217219
#
218220
def assert_array_equal(
219-
actual: ArrayLike,
220-
desired: ArrayLike,
221+
actual: object,
222+
desired: object,
221223
err_msg: str = "",
222224
verbose: bool = True,
223225
*,
@@ -236,26 +238,26 @@ def assert_array_almost_equal(
236238
#
237239
@overload
238240
def assert_array_less(
239-
x: _NumericArrayLike,
240-
y: _NumericArrayLike,
241+
x: _ArrayLikeTD64_co,
242+
y: _ArrayLikeTD64_co,
241243
err_msg: str = "",
242244
verbose: bool = True,
243245
*,
244246
strict: bool = False,
245247
) -> None: ...
246248
@overload
247249
def assert_array_less(
248-
x: _ArrayLikeTD64_co,
249-
y: _ArrayLikeTD64_co,
250+
x: _ArrayLikeDT64_co,
251+
y: _ArrayLikeDT64_co,
250252
err_msg: str = "",
251253
verbose: bool = True,
252254
*,
253255
strict: bool = False,
254256
) -> None: ...
255257
@overload
256258
def assert_array_less(
257-
x: _ArrayLikeDT64_co,
258-
y: _ArrayLikeDT64_co,
259+
x: _NumericArrayLike,
260+
y: _NumericArrayLike,
259261
err_msg: str = "",
260262
verbose: bool = True,
261263
*,
@@ -302,8 +304,8 @@ def assert_raises_regex(
302304
#
303305
@overload
304306
def assert_allclose(
305-
actual: _ArrayLikeNumber_co | _ArrayLikeObject_co,
306-
desired: _ArrayLikeNumber_co | _ArrayLikeObject_co,
307+
actual: _ArrayLikeTD64_co,
308+
desired: _ArrayLikeTD64_co,
307309
rtol: float = 1e-7,
308310
atol: float = 0,
309311
equal_nan: bool = True,
@@ -314,8 +316,8 @@ def assert_allclose(
314316
) -> None: ...
315317
@overload
316318
def assert_allclose(
317-
actual: _ArrayLikeTD64_co,
318-
desired: _ArrayLikeTD64_co,
319+
actual: _NumericArrayLike,
320+
desired: _NumericArrayLike,
319321
rtol: float = 1e-7,
320322
atol: float = 0,
321323
equal_nan: bool = True,

test/static/accept/testing.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ assert_type(np.testing.assert_allclose(AR_i8, AR_f8, verbose=False), None)
167167

168168
assert_type(np.testing.assert_array_almost_equal_nulp(AR_i8, AR_f8, nulp=2), None)
169169

170-
assert_type(np.testing.assert_array_max_ulp(AR_i8, AR_f8, maxulp=2), npt.NDArray[Any])
171-
assert_type(np.testing.assert_array_max_ulp(AR_i8, AR_f8, dtype=np.float32), npt.NDArray[Any])
170+
assert_type(np.testing.assert_array_max_ulp(AR_i8, AR_f8, maxulp=2), npt.NDArray[np.floating])
171+
assert_type(np.testing.assert_array_max_ulp(AR_i8, AR_f8, dtype=np.float32), npt.NDArray[np.floating])
172172

173173
assert_type(np.testing.assert_warns(RuntimeWarning), contextlib._GeneratorContextManager[None])
174174
assert_type(np.testing.assert_warns(RuntimeWarning, func3, 5), bool)

test/static/reject/testing.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import numpy.typing as npt
33

44
AR_U: npt.NDArray[np.str_]
55

6-
def func() -> bool: ...
6+
def func(x: object) -> bool: ...
77

88
np.testing.assert_(True, msg=1) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] # noqa: PT009
99
np.testing.build_err_msg(1, "test") # type: ignore[arg-type] # pyright: ignore[reportArgumentType]
@@ -20,9 +20,9 @@ np.testing.assert_allclose(AR_U, AR_U) # type: ignore[arg-type] # pyright: ign
2020
np.testing.assert_array_almost_equal_nulp(AR_U, AR_U) # type: ignore[arg-type] # pyright: ignore[reportArgumentType]
2121
np.testing.assert_array_max_ulp(AR_U, AR_U) # type: ignore[arg-type] # pyright: ignore[reportArgumentType]
2222

23-
np.testing.assert_warns(warning_class=RuntimeWarning, func=func) # type: ignore[call-overload] # pyright: ignore[reportCallIssue]
23+
np.testing.assert_warns(RuntimeWarning, func) # type: ignore[call-overload] # pyright: ignore[reportCallIssue]
2424
np.testing.assert_no_warnings(func=func) # type: ignore[call-overload] # pyright: ignore[reportCallIssue]
25-
np.testing.assert_no_warnings(func, None) # type: ignore[call-overload] # pyright: ignore[reportCallIssue]
26-
np.testing.assert_no_warnings(func, test=None) # type: ignore[call-overload] # pyright: ignore[reportCallIssue]
25+
np.testing.assert_no_warnings(func) # type: ignore[call-overload] # pyright: ignore[reportCallIssue]
26+
np.testing.assert_no_warnings(func, y=None) # type: ignore[call-overload] # pyright: ignore[reportCallIssue]
2727

2828
np.testing.assert_no_gc_cycles(func=func) # type: ignore[call-overload] # pyright: ignore[reportCallIssue]

0 commit comments

Comments
 (0)