Skip to content

Commit acf1dad

Browse files
committed
🐴 work around false-positive mypy errors
1 parent 8c15182 commit acf1dad

File tree

3 files changed

+15
-28
lines changed

3 files changed

+15
-28
lines changed

src/_numtype/@test/test_nep50.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ i8_to_i2: CanCast0D[Any, np.int64] = i2 # type: ignore[assignment] # pyright:
285285
i8_to_u2: CanCast0D[Any, np.int64] = u2 # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
286286
i8_to_i4: CanCast0D[Any, np.int64] = i4 # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
287287
i8_to_u4: CanCast0D[Any, np.int64] = u4 # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
288-
i8_to_i8: CanCast0D[Any, np.int64] = i8 # NOTE: This accepts `signedinteger` for convenience
288+
i8_to_i8: CanCast0D[Any, np.int64] = i8 # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
289289
i8_to_u8: CanCast0D[Any, np.int64] = u8 # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
290290
i8_to_f2: CanCast0D[Any, np.int64] = f2 # type: ignore[assignment] # pyright: ignore[reportAssignmentType]
291291
i8_to_f4: CanCast0D[Any, np.int64] = f4 # type: ignore[assignment] # pyright: ignore[reportAssignmentType]

src/_numtype/_nep50.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ __all__ = ["CanCast0D", "CanCastND", "CanNEP50", "MatchND", "PromoteWith", "Prom
1111

1212
_T_co = TypeVar("_T_co", covariant=True)
1313
_BelowT_contra = TypeVar("_BelowT_contra", bound=np.generic, contravariant=True)
14-
_AboveT_contra = TypeVar("_AboveT_contra", bound=np.generic, contravariant=True, default=Any)
14+
_AboveT_contra = TypeVar("_AboveT_contra", contravariant=True, default=Any)
1515
_OtherT_contra = TypeVar("_OtherT_contra", contravariant=True)
1616
_MatchT_co = TypeVar("_MatchT_co", bound=np.generic, covariant=True, default=Any)
1717
_ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], covariant=True)
@@ -49,7 +49,8 @@ _OutT = TypeVar("_OutT", bound=np.generic)
4949

5050
PromoteWith = TypeAliasType(
5151
"PromoteWith",
52-
_CanNEP50Rule0[_WithT, _OutT]
52+
CanNEP50[Any, _WithT, _OutT]
53+
| _CanNEP50Rule0[_WithT, _OutT]
5354
| _CanNEP50Rule1[_WithT, _OutT]
5455
| _CanNEP50Rule2[_WithT, _OutT]
5556
| _CanNEP50Rule3[_WithT, _OutT]

src/numpy-stubs/__init__.pyi

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,8 +1961,6 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
19611961
@overload
19621962
def __add__(self: NDArray[_ScalarT], x: _nt.CanCastND[Any, _ScalarT], /) -> NDArray[_ScalarT]: ... # type: ignore[overload-overlap]
19631963
@overload
1964-
def __add__(self: NDArray[_ScalarT], x: _nt.CanCastND[Any, Any, _ScalarT, _ScalarT2], /) -> NDArray[_ScalarT2]: ... # type: ignore[overload-overlap]
1965-
@overload
19661964
def __add__(self: NDArray[_ScalarT], x: _nt.MatchND[Any, _nt.PromoteWith[_ScalarT, _ScalarT2]], /) -> NDArray[_ScalarT2]: ... # type: ignore[overload-overlap]
19671965
@overload
19681966
def __add__(self: NDArray[generic[_AnyItemT]], x: _nt.SequenceND[_AnyItemT], /) -> ndarray[tuple[int, ...], _DTypeT_co]: ...
@@ -1981,8 +1979,6 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
19811979
@overload
19821980
def __radd__(self: NDArray[_ScalarT], x: _nt.CanCastND[Any, _ScalarT], /) -> NDArray[_ScalarT]: ... # type: ignore[overload-overlap]
19831981
@overload
1984-
def __radd__(self: NDArray[_ScalarT], x: _nt.CanCastND[Any, Any, _ScalarT, _ScalarT2], /) -> NDArray[_ScalarT2]: ... # type: ignore[overload-overlap]
1985-
@overload
19861982
def __radd__(self: NDArray[_ScalarT], x: _nt.MatchND[Any, _nt.PromoteWith[_ScalarT, _ScalarT2]], /) -> NDArray[_ScalarT2]: ... # type: ignore[overload-overlap]
19871983
@overload
19881984
def __radd__(self: NDArray[generic[_AnyItemT]], x: _nt.SequenceND[_AnyItemT], /) -> ndarray[tuple[int, ...], _DTypeT_co]: ...
@@ -4043,6 +4039,9 @@ class integer(_IntegralMixin, _RoundMixin, number[_BitT, int]):
40434039
above: bool_,
40444040
/,
40454041
) -> integer: ...
4042+
@type_check_only
4043+
def __nep50_rule4__(self, other: _JustSignedInteger, /) -> signedinteger | float64: ...
4044+
@type_check_only
40464045
def __nep50_rule5__(self, other: _nt.Just[integer], /) -> integer | float64: ...
40474046

40484047
#
@@ -4056,35 +4055,23 @@ class integer(_IntegralMixin, _RoundMixin, number[_BitT, int]):
40564055

40574056
#
40584057
@overload
4059-
def __add__(self, x: int, /) -> Self: ...
4058+
def __add__(self, x: _nt.CanCast0D[Self] | int, /) -> Self: ...
40604059
@overload
40614060
def __add__(self, x: _nt.JustFloat, /) -> float64: ...
40624061
@overload
40634062
def __add__(self, x: _nt.JustComplex, /) -> complex128: ...
40644063
@overload
4065-
def __add__(self, x: _nt.CanCast0D[Self], /) -> Self: ...
4066-
@overload
4067-
def __add__(self, x: _nt.CanCast0D[Any, Self, _ScalarT], /) -> _ScalarT: ...
4068-
@overload
4069-
def __add__(self, x: _nt.PromoteWith0D[Self, _ScalarT], /) -> _ScalarT: ...
4070-
@overload
4071-
def __add__(self: _nt.PromoteWith[_ScalarT, _ScalarT2], x: _nt.CanArray0D[_ScalarT], /) -> _ScalarT2: ... # pyright: ignore[reportIncompatibleMethodOverride]
4064+
def __add__(self, x: _nt.PromoteWith0D[Self, _ScalarT], /) -> _ScalarT: ... # pyright: ignore[reportIncompatibleMethodOverride]
40724065

40734066
#
40744067
@overload
4075-
def __radd__(self, x: int, /) -> Self: ...
4068+
def __radd__(self, x: _nt.CanCast0D[Self] | int, /) -> Self: ...
40764069
@overload
40774070
def __radd__(self, x: _nt.JustFloat, /) -> float64: ...
40784071
@overload
40794072
def __radd__(self, x: _nt.JustComplex, /) -> complex128: ...
40804073
@overload
4081-
def __radd__(self, x: _nt.CanCast0D[Self], /) -> Self: ...
4082-
@overload
4083-
def __radd__(self, x: _nt.CanCast0D[Any, Self, _ScalarT], /) -> _ScalarT: ...
4084-
@overload
4085-
def __radd__(self, x: _nt.PromoteWith0D[Self, _ScalarT], /) -> _ScalarT: ...
4086-
@overload
4087-
def __radd__(self: _nt.PromoteWith[_ScalarT, _ScalarT2], x: _nt.CanArray0D[_ScalarT], /) -> _ScalarT2: ... # pyright: ignore[reportIncompatibleMethodOverride]
4074+
def __radd__(self, x: _nt.PromoteWith0D[Self, _ScalarT], /) -> _ScalarT: ... # pyright: ignore[reportIncompatibleMethodOverride]
40884075

40894076
# keep in sync with __add__
40904077
@overload
@@ -4250,10 +4237,11 @@ class signedinteger(integer[_BitT]):
42504237
/,
42514238
) -> signedinteger: ...
42524239
@type_check_only
4253-
def __nep50_rule0__(self, other: uint32, /) -> int64: ...
4240+
def __nep50_rule0__(self, other: uint32 | int64, /) -> int64: ...
42544241
@type_check_only
42554242
def __nep50_rule1__(self, other: uint64, /) -> float64: ...
42564243
@type_check_only
4244+
@override
42574245
def __nep50_rule4__(self, other: _JustSignedInteger, /) -> signedinteger: ...
42584246
@type_check_only
42594247
@override
@@ -4453,8 +4441,6 @@ class unsignedinteger(integer[_BitT]):
44534441
) -> unsignedinteger: ...
44544442
@type_check_only
44554443
def __nep50_rule3__(self, other: _JustUnsignedInteger, /) -> unsignedinteger: ...
4456-
@type_check_only
4457-
def __nep50_rule4__(self, other: _JustSignedInteger, /) -> signedinteger | float64: ...
44584444

44594445
#
44604446
@property
@@ -7042,7 +7028,7 @@ class int64(_IntROpMixin[int64], signedinteger[_n._64]): # type: ignore[misc]
70427028
def __nep50__(
70437029
self,
70447030
below: int64 | float64 | complex128 | longdouble | clongdouble | timedelta64,
7045-
above: signedinteger | uint32 | uint16 | uint8 | bool_,
7031+
above: int32 | uint32 | int16 | uint16 | int8 | uint8 | bool_,
70467032
/,
70477033
) -> int64: ...
70487034
@type_check_only
@@ -7052,7 +7038,7 @@ class int64(_IntROpMixin[int64], signedinteger[_n._64]): # type: ignore[misc]
70527038
def __nep50_rule2__(self, other: complex64, /) -> complex128: ...
70537039
@type_check_only
70547040
@override
7055-
def __nep50_rule4__(self, other: _JustSignedInteger, /) -> Self: ...
7041+
def __nep50_rule4__(self, other: _JustSignedInteger | signedinteger, /) -> Self: ...
70567042
@type_check_only
70577043
@override
70587044
def __nep50_rule5__(self, other: _nt.Just[integer] | _JustUnsignedInteger, /) -> Self | float64: ...

0 commit comments

Comments
 (0)