Skip to content

Commit ae631fd

Browse files
jorenhamcharris
authored andcommitted
TYP: Work around a mypy issue with bool arrays (#29248)
1 parent ae79bb4 commit ae631fd

File tree

5 files changed

+8
-7
lines changed

5 files changed

+8
-7
lines changed

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies:
2525
- hypothesis
2626
# For type annotations
2727
- typing_extensions>=4.5.0
28-
- mypy=1.15.0
28+
- mypy=1.16.1
2929
- orjson # makes mypy faster
3030
# For building docs
3131
- sphinx>=4.5.0

numpy/__init__.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3814,14 +3814,14 @@ class bool(generic[_BoolItemT_co], Generic[_BoolItemT_co]):
38143814
@property
38153815
def imag(self) -> np.bool[L[False]]: ...
38163816

3817-
@overload
3818-
def __init__(self: np.bool[L[False]], /) -> None: ...
3817+
@overload # mypy bug workaround: https://github.com/numpy/numpy/issues/29245
3818+
def __init__(self: np.bool[builtins.bool], value: Never, /) -> None: ...
38193819
@overload
38203820
def __init__(self: np.bool[L[False]], value: _Falsy = ..., /) -> None: ...
38213821
@overload
38223822
def __init__(self: np.bool[L[True]], value: _Truthy, /) -> None: ...
38233823
@overload
3824-
def __init__(self, value: object, /) -> None: ...
3824+
def __init__(self: np.bool[builtins.bool], value: object, /) -> None: ...
38253825

38263826
def __bool__(self, /) -> _BoolItemT_co: ...
38273827
@overload

numpy/typing/tests/data/reveal/array_constructors.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ assert_type(np.array(B, subok=True), SubClass[np.float64])
3939
assert_type(np.array(B, subok=True, ndmin=0), SubClass[np.float64])
4040
assert_type(np.array(B, subok=True, ndmin=1), SubClass[np.float64])
4141
assert_type(np.array(D), npt.NDArray[np.float64 | np.int64])
42+
# https://github.com/numpy/numpy/issues/29245
43+
assert_type(np.array([], dtype=np.bool), npt.NDArray[np.bool])
4244

4345
assert_type(np.zeros([1, 5, 6]), npt.NDArray[np.float64])
4446
assert_type(np.zeros([1, 5, 6], dtype=np.int64), npt.NDArray[np.int64])

numpy/typing/tests/data/reveal/ma.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,7 @@ assert_type(MAR_b.swapaxes(0, 1), MaskedArray[np.bool])
343343
assert_type(MAR_2d_f4.swapaxes(1, 0), MaskedArray[np.float32])
344344

345345
assert_type(np.ma.nomask, np.bool[Literal[False]])
346-
# https://github.com/python/mypy/issues/18974
347-
assert_type(np.ma.MaskType, type[np.bool]) # type: ignore[assert-type]
346+
assert_type(np.ma.MaskType, type[np.bool])
348347

349348
assert_type(MAR_1d.__setmask__([True, False]), None)
350349
assert_type(MAR_1d.__setmask__(np.False_), None)

requirements/test_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pytest-timeout
1313
# For testing types. Notes on the restrictions:
1414
# - Mypy relies on C API features not present in PyPy
1515
# NOTE: Keep mypy in sync with environment.yml
16-
mypy==1.15.0; platform_python_implementation != "PyPy"
16+
mypy==1.16.1; platform_python_implementation != "PyPy"
1717
typing_extensions>=4.5.0
1818
# for optional f2py encoding detection
1919
charset-normalizer

0 commit comments

Comments
 (0)