8000 TYP: fix `NDArray[integer]` inplace operator mypy issue · numpy/numpy@7229699 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7229699

Browse files
jorenhamcharris
authored andcommitted
TYP: fix NDArray[integer] inplace operator mypy issue
1 parent 141fb34 commit 7229699

File tree

3 files changed

+23
-130
lines changed

3 files changed

+23
-130
lines changed

numpy/__init__.pyi

Lines changed: 12 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -3362,13 +3362,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
33623362
@overload
33633363
def __iadd__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
33643364
@overload
3365-
def __iadd__(
3366-
self: NDArray[unsignedinteger],
3367-
other: _ArrayLikeUInt_co | _IntLike_co,
3368-
/,
3369-
) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3370-
@overload
3371-
def __iadd__(self: NDArray[signedinteger], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3365+
def __iadd__(self: NDArray[integer], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
33723366
@overload
33733367
def __iadd__(self: NDArray[floating], other: _ArrayLikeFloat_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
33743368
@overload
@@ -3388,13 +3382,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
33883382

33893383
#
33903384
@overload
3391-
def __isub__(
3392-
self: NDArray[unsignedinteger],
3393-
other: _ArrayLikeUInt_co | _IntLike_co,
3394-
/,
3395-
) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3396-
@overload
3397-
def __isub__(self: NDArray[signedinteger], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3385+
def __isub__(self: NDArray[integer], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
33983386
@overload
33993387
def __isub__(self: NDArray[floating], other: _ArrayLikeFloat_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
34003388
@overload
@@ -3409,15 +3397,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
34093397
def __imul__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
34103398
@overload
34113399
def __imul__(
3412-
self: NDArray[unsignedinteger],
3413-
other: _ArrayLikeUInt_co | _IntLike_co,
3414-
/,
3415-
) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3416-
@overload
3417-
def __imul__(
3418-
self: ndarray[Any, dtype[signedinteger | character] | dtypes.StringDType],
3419-
other: _ArrayLikeInt_co,
3420-
/,
3400+
self: ndarray[Any, dtype[integer | character] | dtypes.StringDType], other: _ArrayLikeInt_co, /
34213401
) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
34223402
@overload
34233403
def __imul__(self: NDArray[floating | timedelta64], other: _ArrayLikeFloat_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
@@ -3427,13 +3407,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
34273407
def __imul__(self: NDArray[object_], other: Any, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
34283408

34293409
@overload
3430-
def __ipow__(
3431-
self: NDArray[unsignedinteger],
3432-
other: _ArrayLikeUInt_co | _IntLike_co,
3433-
/,
3434-
) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3435-
@overload
3436-
def __ipow__(self: NDArray[signedinteger], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3410+
def __ipow__(self: NDArray[integer], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
34373411
@overload
34383412
def __ipow__(self: NDArray[floating], other: _ArrayLikeFloat_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
34393413
@overload
@@ -3451,27 +3425,15 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
34513425

34523426
# keep in sync with `__imod__`
34533427
@overload
3454-
def __ifloordiv__(
3455-
self: NDArray[unsignedinteger],
3456-
other: _ArrayLikeUInt_co | _IntLike_co,
3457-
/,
3458-
) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3459-
@overload
3460-
def __ifloordiv__(self: NDArray[signedinteger], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3428+
def __ifloordiv__(self: NDArray[integer], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
34613429
@overload
34623430
def __ifloordiv__(self: NDArray[floating | timedelta64], other: _ArrayLikeFloat_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
34633431
@overload
34643432
def __ifloordiv__(self: NDArray[object_], other: Any, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
34653433

34663434
# keep in sync with `__ifloordiv__`
34673435
@overload
3468-
def __imod__(
3469-
self: NDArray[unsignedinteger],
3470-
other: _ArrayLikeUInt_co | _IntLike_co,
3471-
/,
3472-
) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3473-
@overload
3474-
def __imod__(self: NDArray[signedinteger], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3436+
def __imod__(self: NDArray[integer], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
34753437
@overload
34763438
def __imod__(self: NDArray[floating], other: _ArrayLikeFloat_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
34773439
@overload
@@ -3485,77 +3447,45 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
34853447

34863448
# keep in sync with `__irshift__`
34873449
@overload
3488-
def __ilshift__(
3489-
self: NDArray[unsignedinteger],
3490-
other: _ArrayLikeUInt_co | _IntLike_co,
3491-
/,
3492-
) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3493-
@overload
3494-
def __ilshift__(self: NDArray[signedinteger], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3450+
def __ilshift__(self: NDArray[integer], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
34953451
@overload
34963452
def __ilshift__(self: NDArray[object_], other: Any, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
34973453

34983454
# keep in sync with `__ilshift__`
34993455
@overload
3500-
def __irshift__(
3501-
self: NDArray[unsignedinteger],
3502-
other: _ArrayLikeUInt_co | _IntLike_co,
3503-
/,
3504-
) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3505-
@overload
3506-
def __irshift__(self: NDArray[signedinteger], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3456+
def __irshift__(self: NDArray[integer], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
35073457
@overload
35083458
def __irshift__(self: NDArray[object_], other: Any, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
35093459

35103460
# keep in sync with `__ixor__` and `__ior__`
35113461
@overload
35123462
def __iand__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
35133463
@overload
3514-
def __iand__(
3515-
self: NDArray[unsignedinteger],
3516-
other: _ArrayLikeUInt_co | _IntLike_co,
3517-
/,
3518-
) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3519-
@overload
3520-
def __iand__(self: NDArray[signedinteger], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3464+
def __iand__(self: NDArray[integer], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
35213465
@overload
35223466
def __iand__(self: NDArray[object_], other: Any, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
35233467

35243468
# keep in sync with `__iand__` and `__ior__`
35253469
@overload
35263470
def __ixor__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
35273471
@overload
3528-
def __ixor__(
3529-
self: NDArray[unsignedinteger],
3530-
other: _ArrayLikeUInt_co | _IntLike_co,
3531-
/,
3532-
) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3533-
@overload
3534-
def __ixor__(self: NDArray[signedinteger], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3472+
def __ixor__(self: NDArray[integer], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
35353473
@overload
35363474
def __ixor__(self: NDArray[object_], other: Any, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
35373475

35383476
# keep in sync with `__iand__` and `__ixor__`
35393477
@overload
35403478
def __ior__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
35413479
@overload
3542-
def __ior__(
3543-
self: NDArray[unsignedinteger],
3544-
other: _ArrayLikeUInt_co | _IntLike_co,
3545-
/,
3546-
) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3547-
@overload
3548-
def __ior__(self: NDArray[signedinteger], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3480+
def __ior__(self: NDArray[integer], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
35493481
@overload
35503482
def __ior__(self: NDArray[object_], other: Any, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
35513483

35523484
#
35533485
@overload
35543486
def __imatmul__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
35553487
@overload
3556-
def __imatmul__(self: NDArray[unsignedinteger], other: _ArrayLikeUInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3557-
@overload
3558-
def __imatmul__(self: NDArray[signedinteger], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
3488+
def __imatmul__(self: NDArray[integer], other: _ArrayLikeInt_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
35593489
@overload
35603490
def __imatmul__(self: NDArray[floating], other: _ArrayLikeFloat_co, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
35613491
@overload

numpy/ma/core.pyi

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -476,20 +476,13 @@ class MaskedArray(ndarray[_ShapeT_co, _DTypeT_co]):
476476
def __pow__(self, other, mod: None = None, /): ...
477477
def __rpow__(self, other, mod: None = None, /): ...
478478

479-
# Keep in sync with `ndarray.__iadd__`, except that `_MaskedArray[unsignedinteger]` does not accept
480-
# _IntLike_co for `other`.
479+
# Keep in sync with `ndarray.__iadd__`
481480
@overload
482481
def __iadd__(
483482
self: _MaskedArray[np.bool], other: _ArrayLikeBool_co, /
484483
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
485484
@overload
486-
def __iadd__(
487-
self: _MaskedArray[unsignedinteger], other: _ArrayLikeUInt_co, /
488-
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
489-
@overload
490-
def __iadd__(
491-
self: _MaskedArray[signedinteger], other: _ArrayLikeInt_co, /
492-
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
485+
def __iadd__(self: _MaskedArray[integer], other: _ArrayLikeInt_co, /) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
493486
@overload
494487
def __iadd__(
495488
self: _MaskedArray[floating], other: _ArrayLikeFloat_co, /
@@ -515,16 +508,9 @@ class MaskedArray(ndarray[_ShapeT_co, _DTypeT_co]):
515508
self: _MaskedArray[object_], other: Any, /
516509
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
517510

518-
# Keep in sync with `ndarray.__isub__`, except that `_MaskedArray[unsignedinteger]` does not accept
519-
# _IntLike_co for `other`.
520-
@overload
521-
def __isub__(
522-
self: _MaskedArray[unsignedinteger], other: _ArrayLikeUInt_co, /
523-
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
511+
# Keep in sync with `ndarray.__isub__`
524512
@overload
525-
def __isub__(
526-
self: _MaskedArray[signedinteger], other: _ArrayLikeInt_co, /
527-
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
513+
def __isub__(self: _MaskedArray[integer], other: _ArrayLikeInt_co, /) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
528514
@overload
529515
def __isub__(
530516
self: _MaskedArray[floating], other: _ArrayLikeFloat_co, /
@@ -542,20 +528,14 @@ class MaskedArray(ndarray[_ShapeT_co, _DTypeT_co]):
542528
self: _MaskedArray[object_], other: Any, /
543529
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
544530

545-
# Keep in sync with `ndarray.__imul__`, except that `_MaskedArray[unsignedinteger]` does not accept
546-
# _IntLike_co for `other`.
531+
# Keep in sync with `ndarray.__imul__`
547532
@overload
548533
def __imul__(
549534
self: _MaskedArray[np.bool], other: _ArrayLikeBool_co, /
550535
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
551536
@overload
552537
def __imul__(
553-
self: _MaskedArray[unsignedinteger], other: _ArrayLikeUInt_co, /
554-
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
555-
@overload
556-
def __imul__(
557-
self: MaskedArray[Any, dtype[signedinteger] | dtype[character] | dtypes.StringDType],
558-
other: _ArrayLikeInt_co, /
538+
self: MaskedArray[Any, dtype[integer] | dtype[character] | dtypes.StringDType], other: _ArrayLikeInt_co, /
559539
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
560540
@overload
561541
def __imul__(
@@ -570,16 +550,9 @@ class MaskedArray(ndarray[_ShapeT_co, _DTypeT_co]):
570550
self: _MaskedArray[object_], other: Any, /
571551
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
572552

573-
# Keep in sync with `ndarray.__ifloordiv__`, except that `_MaskedArray[unsignedinteger]` does not accept
574-
# _IntLike_co for `other`.
575-
@overload
576-
def __ifloordiv__(
577-
self: _MaskedArray[unsignedinteger], other: _ArrayLikeUInt_co, /
578-
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
553+
# Keep in sync with `ndarray.__ifloordiv__`
579554
@overload
580-
def __ifloordiv__(
581-
self: _MaskedArray[signedinteger], other: _ArrayLikeInt_co, /
582-
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
555+
def __ifloordiv__(self: _MaskedArray[integer], other: _ArrayLikeInt_co, /) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
583556
@overload
584557
def __ifloordiv__(
585558
self: _MaskedArray[floating | timedelta64], other: _ArrayLikeFloat_co, /
@@ -589,8 +562,7 @@ class MaskedArray(ndarray[_ShapeT_co, _DTypeT_co]):
589562
self: _MaskedArray[object_], other: Any, /
590563
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
591564

592-
# Keep in sync with `ndarray.__itruediv__`, except that `_MaskedArray[unsignedinteger]` does not accept
593-
# _IntLike_co for `other`.
565+
# Keep in sync with `ndarray.__itruediv__`
594566
@overload
595567
def __itruediv__(
596568
self: _MaskedArray[floating | timedelta64], other: _ArrayLikeFloat_co, /
@@ -606,16 +578,9 @@ class MaskedArray(ndarray[_ShapeT_co, _DTypeT_co]):
606578
self: _MaskedArray[object_], other: Any, /
607579
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
608580

609-
# Keep in sync with `ndarray.__ipow__`, except that `_MaskedArray[unsignedinteger]` does not accept
610-
# _IntLike_co for `other`.
581+
# Keep in sync with `ndarray.__ipow__`
611582
@overload
612-
def __ipow__(
613-
self: _MaskedArray[unsignedinteger], other: _ArrayLikeUInt_co, /
614-
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
615-
@overload
616-
def __ipow__(
617-
self: _MaskedArray[signedinteger], other: _ArrayLikeInt_co, /
618-
) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
583+
def __ipow__(self: _MaskedArray[integer], other: _ArrayLikeInt_co, /) -> MaskedArray[_ShapeT_co, _DTypeT_co]: ...
619584
@overload
620585
def __ipow__(
621586
self: _MaskedArray[floating], other: _ArrayLikeFloat_co, /

numpy/typing/tests/data/fail/arithmetic.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ AR_b *= AR_LIKE_f # type: ignore[arg-type]
8585
AR_b *= AR_LIKE_c # type: ignore[arg-type]
8686
AR_b *= AR_LIKE_m # type: ignore[arg-type]
8787

88-
AR_u *= AR_LIKE_i # type: ignore[arg-type]
8988
AR_u *= AR_LIKE_f # type: ignore[arg-type]
9089
AR_u *= AR_LIKE_c # type: ignore[arg-type]
9190
AR_u *= AR_LIKE_m # type: ignore[arg-type]
@@ -105,7 +104,6 @@ AR_b **= AR_LIKE_i # type: ignore[misc]
105104
AR_b **= AR_LIKE_f # type: ignore[misc]
106105
AR_b **= AR_LIKE_c # type: ignore[misc]
107106

108-
AR_u **= AR_LIKE_i # type: ignore[arg-type]
109107
AR_u **= AR_LIKE_f # type: ignore[arg-type]
110108
AR_u **= AR_LIKE_c # type: ignore[arg-type]
111109

0 commit comments

Comments
 (0)
0