Skip to content

Commit 79a4043

Browse files
committed
✅ fix the remaining failing ndarray arithmetic binop tests
1 parent 9c3cdbf commit 79a4043

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

src/numpy-stubs/@test/static/reject/arithmetic.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ AR_f *= AR_LIKE_m # type: ignore[arg-type] # pyright: ignore[reportOperatorIss
8989

9090
# Array power
9191

92-
AR_b **= AR_LIKE_b # type: ignore[arg-type] # pyright: ignore[reportOperatorIssue, reportUnknownVariableType]
93-
AR_b **= AR_LIKE_u # type: ignore[arg-type] # pyright: ignore[reportOperatorIssue, reportUnknownVariableType]
92+
AR_b **= AR_LIKE_b # type: ignore[arg-type] # pyright: ignore[reportAssignmentType]
93+
AR_b **= AR_LIKE_u # type: ignore[arg-type] # pyright: ignore[reportAssignmentType]
9494
AR_b **= AR_LIKE_i # type: ignore[arg-type] # pyright: ignore[reportAssignmentType]
9595
AR_b **= AR_LIKE_f # type: ignore[arg-type] # pyright: ignore[reportAssignmentType]
9696
AR_b **= AR_LIKE_c # type: ignore[arg-type] # pyright: ignore[reportAssignmentType]

src/numpy-stubs/__init__.pyi

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ _FloatingT = TypeVar("_FloatingT", bound=floating)
656656
_ComplexFloatingT = TypeVar("_ComplexFloatingT", bound=complexfloating)
657657
_InexactT = TypeVar("_InexactT", bound=inexact)
658658
_NumberT = TypeVar("_NumberT", bound=number)
659+
_NumericT = TypeVar("_NumericT", bound=number | timedelta64)
659660
_CoNumberT = TypeVar("_CoNumberT", bound=bool_ | number)
660661
_CharT = TypeVar("_CharT", bound=character)
661662

@@ -2209,13 +2210,13 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
22092210
self: NDArray[generic[_T]], x: _nt.Sequence1ND[_nt.op.CanRAdd[_T, _T]], /
22102211
) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
22112212

2212-
# TODO(jorenham): reject `bool_ - bool_`
2213+
#
22132214
@overload
2214-
def __sub__(self: NDArray[_ScalarT], x: _nt.Casts[_ScalarT], /) -> NDArray[_ScalarT]: ... # type: ignore[overload-overlap]
2215+
def __sub__(self: NDArray[_NumericT], x: _nt.Casts[_NumericT], /) -> NDArray[_NumericT]: ... # type: ignore[overload-overlap]
22152216
@overload
22162217
def __sub__(self: NDArray[_SelfScalarT], x: _nt.CastsWith[_SelfScalarT, _ScalarT], /) -> NDArray[_ScalarT]: ... # type: ignore[overload-overlap]
22172218
@overload
2218-
def __sub__(self: _nt.CastsWithBuiltin[_T, _ScalarT], x: _nt.SequenceND[_T], /) -> NDArray[_ScalarT]: ...
2219+
def __sub__(self: _nt.CastsWithBuiltin[_T, _NumericT], x: _nt.SequenceND[_T], /) -> NDArray[_NumericT]: ...
22192220
@overload
22202221
def __sub__(self: _nt.CastsWithInt[_ScalarT], x: _nt.SequenceND[_nt.JustInt], /) -> NDArray[_ScalarT]: ...
22212222
@overload
@@ -2229,19 +2230,15 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
22292230
@overload
22302231
def __sub__(self: NDArray[object_], x: object, /) -> NDArray[object_]: ... # type: ignore[overload-cannot-match]
22312232
@overload
2232-
def __sub__(self: NDArray[str_], x: _nt.ToString_nd[_T], /) -> _nt.StringArrayND[_T]: ...
2233-
@overload
2234-
def __sub__(self: _nt.StringArrayND[_T], x: _nt.ToString_nd[_T] | _nt.ToStr_nd, /) -> _nt.StringArrayND[_T]: ...
2235-
@overload
22362233
def __sub__(self: NDArray[generic[_T]], x: _nt.Sequence1ND[_nt.op.CanRSub[_T]], /) -> NDArray[Incomplete]: ...
22372234

22382235
#
22392236
@overload
2240-
def __rsub__(self: NDArray[_ScalarT], x: _nt.Casts[_ScalarT], /) -> NDArray[_ScalarT]: ... # type: ignore[overload-overlap]
2237+
def __rsub__(self: NDArray[_NumericT], x: _nt.Casts[_NumericT], /) -> NDArray[_NumericT]: ... # type: ignore[overload-overlap]
22412238
@overload
22422239
def __rsub__(self: NDArray[_SelfScalarT], x: _nt.CastsWith[_SelfScalarT, _ScalarT], /) -> NDArray[_ScalarT]: ... # type: ignore[overload-overlap]
22432240
@overload
2244-
def __rsub__(self: _nt.CastsWithBuiltin[_T, _ScalarT], x: _nt.SequenceND[_T], /) -> NDArray[_ScalarT]: ...
2241+
def __rsub__(self: _nt.CastsWithBuiltin[_T, _NumericT], x: _nt.SequenceND[_T], /) -> NDArray[_NumericT]: ...
22452242
@overload
22462243
def __rsub__(self: _nt.CastsWithInt[_ScalarT], x: _nt.SequenceND[_nt.JustInt], /) -> NDArray[_ScalarT]: ...
22472244
@overload
@@ -2255,10 +2252,6 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
22552252
@overload
22562253
def __rsub__(self: NDArray[object_], x: object, /) -> NDArray[object_]: ... # type: ignore[overload-cannot-match]
22572254
@overload
2258-
def __rsub__(self: NDArray[str_], x: _nt.ToString_nd[_T], /) -> _nt.StringArrayND[_T]: ...
2259-
@overload
2260-
def __rsub__(self: _nt.StringArrayND[_T], x: _nt.ToString_nd[_T] | _nt.ToStr_nd, /) -> _nt.StringArrayND[_T]: ...
2261-
@overload
22622255
def __rsub__(self: NDArray[generic[_T]], x: _nt.Sequence1ND[_nt.op.CanSub[_T]], /) -> NDArray[Incomplete]: ...
22632256

22642257
#
@@ -2277,10 +2270,6 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
22772270
@overload
22782271
def __isub__(self: NDArray[object_], x: object, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
22792272
@overload
2280-
def __isub__(
2281-
self: _nt.StringArrayND[_T], x: _nt.ToString_nd[_T] | _nt.ToStr_nd, /
2282-
) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
2283-
@overload
22842273
def __isub__(
22852274
self: NDArray[generic[_T]], x: _nt.Sequence1ND[_nt.op.CanRSub[_T, _T]], /
22862275
) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
@@ -2422,9 +2411,13 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
24222411
def __pow__(self: NDArray[_NumberT], x: _nt.Casts[_NumberT], k: None = None, /) -> NDArray[_NumberT]: ...
24232412
@overload
24242413
def __pow__(
2425-
self: NDArray[_NumberT], x: _nt.CastsWith[_NumberT, _ScalarT], k: None = None, /
2414+
self: NDArray[_CoNumberT], x: _nt.CastsWith[_CoNumberT, _ScalarT], k: None = None, /
24262415
) -> NDArray[_ScalarT]: ...
24272416
@overload
2417+
def __pow__(
2418+
self: _nt.CastsWithBuiltin[_T, _NumberT], x: _nt.SequenceND[_T], k: None = None, /
2419+
) -> NDArray[_NumberT]: ...
2420+
@overload
24282421
def __pow__(
24292422
self: _nt.CastsWithInt[_ScalarT], x: _nt.SequenceND[_nt.JustInt], k: None = None, /
24302423
) -> NDArray[_ScalarT]: ...
@@ -2437,16 +2430,22 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
24372430
self: _nt.CastsWithComplex[_ScalarT], x: _nt.SequenceND[_nt.JustComplex], k: None = None, /
24382431
) -> NDArray[_ScalarT]: ...
24392432
@overload
2433+
def __pow__(self: NDArray[bool_], x: _nt.ToBool_nd, k: None = None, /) -> NDArray[int8]: ...
2434+
@overload
24402435
def __pow__(self: NDArray[object_], x: object, k: None = None, /) -> NDArray[object_]: ...
24412436

24422437
#
24432438
@overload
24442439
def __rpow__(self: NDArray[_NumberT], x: _nt.Casts[_NumberT], k: None = None, /) -> NDArray[_NumberT]: ...
24452440
@overload
24462441
def __rpow__(
2447-
self: NDArray[_NumberT], x: _nt.CastsWith[_NumberT, _ScalarT], k: None = None, /
2442+
self: NDArray[_CoNumberT], x: _nt.CastsWith[_CoNumberT, _ScalarT], k: None = None, /
24482443
) -> NDArray[_ScalarT]: ...
24492444
@overload
2445+
def __rpow__(
2446+
self: _nt.CastsWithBuiltin[_T, _NumberT], x: _nt.SequenceND[_T], k: None = None, /
2447+
) -> NDArray[_NumberT]: ...
2448+
@overload
24502449
def __rpow__(
24512450
self: _nt.CastsWithInt[_ScalarT], x: _nt.SequenceND[_nt.JustInt], k: None = None, /
24522451
) -> NDArray[_ScalarT]: ...
@@ -2459,6 +2458,8 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
24592458
self: _nt.CastsWithComplex[_ScalarT], x: _nt.SequenceND[_nt.JustComplex], k: None = None, /
24602459
) -> NDArray[_ScalarT]: ...
24612460
@overload
2461+
def __rpow__(self: NDArray[bool_], x: _nt.ToBool_nd, k: None = None, /) -> NDArray[int8]: ...
2462+
@overload
24622463
def __rpow__(self: NDArray[object_], x: object, k: None = None, /) -> NDArray[object_]: ...
24632464

24642465
#
@@ -2477,14 +2478,18 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
24772478
@overload
24782479
def __truediv__(self: NDArray[_InexactT], x: _nt.Casts[_InexactT], /) -> NDArray[_InexactT]: ...
24792480
@overload
2480-
def __truediv__(self: NDArray[_InexactT], x: _nt.CastsWith[_InexactT, _ScalarT], /) -> NDArray[_ScalarT]: ...
2481+
def __truediv__(self: NDArray[_ScalarT], x: _nt.CastsWith[_ScalarT, _InexactT], /) -> NDArray[_InexactT]: ...
24812482
@overload
24822483
def __truediv__(self: _nt.CastsWithFloat[_ScalarT], x: _nt.SequenceND[float], /) -> NDArray[_ScalarT]: ...
24832484
@overload
24842485
def __truediv__(
24852486
self: _nt.CastsWithComplex[_ScalarT], x: _nt.SequenceND[_nt.JustComplex], /
24862487
) -> NDArray[_ScalarT]: ...
24872488
@overload
2489+
def __truediv__(
2490+
self: _HasDType[_HasType[_JustNumber]], x: _nt.CoFloat64_nd | _HasDType[_HasType[_JustNumber]], /
2491+
) -> NDArray[inexact]: ...
2492+
@overload
24882493
def __truediv__(self: NDArray[_nt.co_integer], x: _nt.CoInteger_nd, /) -> NDArray[float64]: ...
24892494
@overload
24902495
def __truediv__(self: NDArray[timedelta64], x: _nt.ToTimeDelta_nd, /) -> NDArray[float64]: ...
@@ -2501,14 +2506,18 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
25012506
@overload
25022507
def __rtruediv__(self: NDArray[_InexactT], x: _nt.Casts[_InexactT], /) -> NDArray[_InexactT]: ...
25032508
@overload
2504-
def __rtruediv__(self: NDArray[_InexactT], x: _nt.CastsWith[_InexactT, _ScalarT], /) -> NDArray[_ScalarT]: ...
2509+
def __rtruediv__(self: NDArray[_ScalarT], x: _nt.CastsWith[_ScalarT, _InexactT], /) -> NDArray[_InexactT]: ...
25052510
@overload
25062511
def __rtruediv__(self: _nt.CastsWithFloat[_ScalarT], x: _nt.SequenceND[float], /) -> NDArray[_ScalarT]: ...
25072512
@overload
25082513
def __rtruediv__(
25092514
self: _nt.CastsWithComplex[_ScalarT], x: _nt.SequenceND[_nt.JustComplex], /
25102515
) -> NDArray[_ScalarT]: ...
25112516
@overload
2517+
def __rtruediv__(
2518+
self: _HasDType[_HasType[_JustNumber]], x: _nt.CoFloat64_nd | _HasDType[_HasType[_JustNumber]], /
2519+
) -> NDArray[inexact]: ...
2520+
@overload
25122521
def __rtruediv__(self: NDArray[_nt.co_integer], x: _nt.CoInteger_nd, /) -> NDArray[float64]: ...
25132522
@overload
25142523
def __rtruediv__(self: NDArray[timedelta64], x: _nt.ToTimeDelta_nd, /) -> NDArray[float64]: ...

0 commit comments

Comments
 (0)