Skip to content

Commit 004458d

Browse files
authored
TYP: Work around a mypy issue with bool arrays (numpy#29248)
1 parent 7311f0a commit 004458d

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

numpy/__init__.pyi

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

3851-
@overload
3852-
def __init__(self: np.bool[L[False]], /) -> None: ...
3851+
@overload # mypy bug workaround: https://github.com/numpy/numpy/issues/29245
3852+
def __init__(self: np.bool[builtins.bool], value: Never, /) -> None: ...
38533853
@overload
38543854
def __init__(self: np.bool[L[False]], value: _Falsy = ..., /) -> None: ...
38553855
@overload
38563856
def __init__(self: np.bool[L[True]], value: _Truthy, /) -> None: ...
38573857
@overload
3858-
def __init__(self, value: object, /) -> None: ...
3858+
def __init__(self: np.bool[builtins.bool], value: object, /) -> None: ...
38593859

38603860
def __bool__(self, /) -> _BoolItemT_co: ...
38613861
@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
@@ -357,8 +357,7 @@ assert_type(MAR_b.swapaxes(0, 1), MaskedArray[np.bool])
357357
assert_type(MAR_2d_f4.swapaxes(1, 0), MaskedArray[np.float32])
358358

359359
assert_type(np.ma.nomask, np.bool[Literal[False]])
360-
# https://github.com/python/mypy/issues/18974
361-
assert_type(np.ma.MaskType, type[np.bool]) # type: ignore[assert-type]
360+
assert_type(np.ma.MaskType, type[np.bool])
362361

363362
assert_type(MAR_1d.__setmask__([True, False]), None)
364363
assert_type(MAR_1d.__setmask__(np.False_), None)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy