Skip to content

Commit 4d4ec47

Browse files
committed
✅ fix the remaining failing ndarray (bitwise) binop tests
1 parent 6148b13 commit 4d4ec47

File tree

1 file changed

+56
-65
lines changed

1 file changed

+56
-65
lines changed

src/numpy-stubs/__init__.pyi

Lines changed: 56 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -648,11 +648,12 @@ _ScalarT = TypeVar("_ScalarT", bound=generic)
648648
_SelfScalarT = TypeVar("_SelfScalarT", bound=generic)
649649
_ScalarT_co = TypeVar("_ScalarT_co", bound=generic, default=Any, covariant=True)
650650
_IntegralT = TypeVar("_IntegralT", bound=bool_ | integer | object_)
651-
_RealT = TypeVar("_RealT", bound=bool_ | integer | floating)
652651
_RealScalarT = TypeVar("_RealScalarT", bound=bool_ | integer | floating | object_)
653652
_RealNumberT = TypeVar("_RealNumberT", bound=integer | floating)
654653
_IntegerT = TypeVar("_IntegerT", bound=integer)
654+
_CoIntegerT = TypeVar("_CoIntegerT", bound=bool_ | integer)
655655
_FloatingT = TypeVar("_FloatingT", bound=floating)
656+
_CoFloatingT = TypeVar("_CoFloatingT", bound=bool_ | integer | floating)
656657
_ComplexFloatingT = TypeVar("_ComplexFloatingT", bound=complexfloating)
657658
_InexactT = TypeVar("_InexactT", bound=inexact)
658659
_NumberT = TypeVar("_NumberT", bound=number)
@@ -825,7 +826,7 @@ _IntegerCType: TypeAlias = _UnsignedIntegerCType | _SignedIntegerCType
825826
_NumberCType: TypeAlias = _IntegerCType
826827
_GenericCType: TypeAlias = _NumberCType | type[ct.c_bool | ct.c_char | ct.py_object[Any]]
827828

828-
_PyBoolND: TypeAlias = _nt.SequenceND[bool]
829+
_PyBoolND: TypeAlias = _nt.SequenceND[py_bool]
829830
_PyCoIntND: TypeAlias = _nt.SequenceND[int]
830831
_PyCoFloatND: TypeAlias = _nt.SequenceND[float]
831832
_PyCoComplexND: TypeAlias = _nt.SequenceND[complex]
@@ -2617,7 +2618,9 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
26172618
self: NDArray[_RealNumberT], x: _nt.Casts[_RealNumberT] | _nt.ToBool_nd, /
26182619
) -> NDArray[_RealNumberT]: ...
26192620
@overload
2620-
def __mod__(self: NDArray[_RealT], x: _nt.CastsWith[_RealT, _RealScalarT], /) -> NDArray[_RealScalarT]: ...
2621+
def __mod__(
2622+
self: NDArray[_CoFloatingT], x: _nt.CastsWith[_CoFloatingT, _RealScalarT], /
2623+
) -> NDArray[_RealScalarT]: ...
26212624
@overload
26222625
def __mod__(self: _nt.CastsWithInt[_RealScalarT], x: _PyIntND, /) -> NDArray[_RealScalarT]: ...
26232626
@overload
@@ -2637,7 +2640,9 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
26372640
self: NDArray[_RealNumberT], x: _nt.Casts[_RealNumberT] | _nt.ToBool_nd, /
26382641
) -> NDArray[_RealNumberT]: ...
26392642
@overload
2640-
def __rmod__(self: NDArray[_RealT], x: _nt.CastsWith[_RealT, _RealScalarT], /) -> NDArray[_RealScalarT]: ...
2643+
def __rmod__(
2644+
self: NDArray[_CoFloatingT], x: _nt.CastsWith[_CoFloatingT, _RealScalarT], /
2645+
) -> NDArray[_RealScalarT]: ...
26412646
@overload
26422647
def __rmod__(self: _nt.CastsWithInt[_RealScalarT], x: _PyIntND, /) -> NDArray[_RealScalarT]: ...
26432648
@overload
@@ -2674,7 +2679,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
26742679
) -> _2Tuple[NDArray[_RealNumberT]]: ...
26752680
@overload
26762681
def __divmod__(
2677-
self: NDArray[_RealT], x: _nt.CastsWith[_RealT, _RealScalarT], /
2682+
self: NDArray[_CoFloatingT], x: _nt.CastsWith[_CoFloatingT, _RealScalarT], /
26782683
) -> _2Tuple[NDArray[_RealScalarT]]: ...
26792684
@overload
26802685
def __divmod__(self: _nt.CastsWithInt[_RealScalarT], x: _PyIntND, /) -> _2Tuple[NDArray[_RealScalarT]]: ...
@@ -2696,7 +2701,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
26962701
) -> _2Tuple[NDArray[_RealNumberT]]: ...
26972702
@overload
26982703
def __rdivmod__(
2699-
self: NDArray[_RealT], x: _nt.CastsWith[_RealT, _RealScalarT], /
2704+
self: NDArray[_CoFloatingT], x: _nt.CastsWith[_CoFloatingT, _RealScalarT], /
27002705
) -> _2Tuple[NDArray[_RealScalarT]]: ...
27012706
@overload
27022707
def __rdivmod__(self: _nt.CastsWithInt[_RealScalarT], x: _PyIntND, /) -> _2Tuple[NDArray[_RealScalarT]]: ...
@@ -2773,121 +2778,107 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
27732778
@overload
27742779
def __irshift__(self: NDArray[object_], x: object, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
27752780

2776-
# TODO(jorenham): rewrite the binops below
2777-
27782781
#
27792782
@overload
2780-
def __and__(self: NDArray[bool_], rhs: _nt.ToBool_nd, /) -> NDArray[bool_]: ...
2783+
def __and__(self: NDArray[bool_], x: _PyIntND, /) -> NDArray[intp]: ...
27812784
@overload
2782-
def __and__(self: NDArray[unsignedinteger], rhs: _nt.CoUInt64_nd, /) -> NDArray[unsignedinteger]: ...
2785+
def __and__(self: NDArray[_IntegerT], x: _PyCoIntND, /) -> NDArray[_IntegerT]: ...
27832786
@overload
2784-
def __and__(self: NDArray[signedinteger], rhs: _nt.CoInt64_nd, /) -> NDArray[signedinteger]: ...
2787+
def __and__(self: NDArray[_CoIntegerT], x: _nt.Casts[_CoIntegerT] | _PyBoolND, /) -> NDArray[_CoIntegerT]: ...
27852788
@overload
2786-
def __and__(self: NDArray[integer], rhs: _nt.CoInt64_nd, /) -> NDArray[integer]: ...
2789+
def __and__(self: NDArray[_CoIntegerT], x: _nt.CastsWith[_CoIntegerT, _IntegerT], /) -> NDArray[_IntegerT]: ...
27872790
@overload
2788-
def __and__(self: NDArray[object_], rhs: object, /) -> NDArray[object_]: ...
2789-
@overload
2790-
def __and__(self, rhs: _ArrayLikeObject_co, /) -> NDArray[object_]: ...
2791+
def __and__(self: NDArray[object_], x: object, /) -> NDArray[object_]: ...
27912792

27922793
#
27932794
@overload
2794-
def __rand__(self: NDArray[bool_], lhs: _nt.ToBool_nd, /) -> NDArray[bool_]: ...
2795-
@overload
2796-
def __rand__(self: NDArray[unsignedinteger], lhs: _nt.CoUInt64_nd, /) -> NDArray[unsignedinteger]: ...
2795+
def __rand__(self: NDArray[bool_], x: _PyIntND, /) -> NDArray[intp]: ...
27972796
@overload
2798-
def __rand__(self: NDArray[signedinteger], lhs: _nt.CoInt64_nd, /) -> NDArray[signedinteger]: ...
2797+
def __rand__(self: NDArray[_IntegerT], x: _PyCoIntND, /) -> NDArray[_IntegerT]: ...
27992798
@overload
2800-
def __rand__(self: NDArray[integer], lhs: _nt.CoInt64_nd, /) -> NDArray[integer]: ...
2799+
def __rand__(self: NDArray[_CoIntegerT], x: _nt.Casts[_CoIntegerT] | _PyBoolND, /) -> NDArray[_CoIntegerT]: ...
28012800
@overload
2802-
def __rand__(self: NDArray[object_], lhs: object, /) -> NDArray[object_]: ...
2801+
def __rand__(self: NDArray[_CoIntegerT], x: _nt.CastsWith[_CoIntegerT, _IntegerT], /) -> NDArray[_IntegerT]: ...
28032802
@overload
2804-
def __rand__(self, lhs: _ArrayLikeObject_co, /) -> NDArray[object_]: ...
2803+
def __rand__(self: NDArray[object_], x: object, /) -> NDArray[object_]: ...
28052804

28062805
#
28072806
@overload # type: ignore[misc]
2808-
def __iand__(self: NDArray[bool_], rhs: _nt.ToBool_nd, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
2809-
@overload
2810-
def __iand__(self: NDArray[unsignedinteger], rhs: _nt.CoUInt64_nd, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
2807+
def __iand__(self: NDArray[bool_], x: _nt.ToBool_nd, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
28112808
@overload
2812-
def __iand__(self: NDArray[integer], rhs: _nt.CoInt64_nd, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
2809+
def __iand__(
2810+
self: NDArray[_IntegerT], x: _nt.Casts[_IntegerT] | _PyCoIntND, /
2811+
) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
28132812
@overload
2814-
def __iand__(self: NDArray[object_], rhs: object, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
2813+
def __iand__(self: NDArray[object_], x: object, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
28152814

28162815
#
28172816
@overload
2818-
def __xor__(self: NDArray[bool_], rhs: _nt.ToBool_nd, /) -> NDArray[bool_]: ...
2817+
def __xor__(self: NDArray[bool_], x: _PyIntND, /) -> NDArray[intp]: ...
28192818
@overload
2820-
def __xor__(self: NDArray[unsignedinteger], rhs: _nt.CoUInt64_nd, /) -> NDArray[unsignedinteger]: ...
2819+
def __xor__(self: NDArray[_IntegerT], x: _PyCoIntND, /) -> NDArray[_IntegerT]: ...
28212820
@overload
2822-
def __xor__(self: NDArray[signedinteger], rhs: _nt.CoInt64_nd, /) -> NDArray[signedinteger]: ...
2821+
def __xor__(self: NDArray[_CoIntegerT], x: _nt.Casts[_CoIntegerT] | _PyBoolND, /) -> NDArray[_CoIntegerT]: ...
28232822
@overload
2824-
def __xor__(self: NDArray[integer], rhs: _nt.CoInt64_nd, /) -> NDArray[integer]: ...
2823+
def __xor__(self: NDArray[_CoIntegerT], x: _nt.CastsWith[_CoIntegerT, _IntegerT], /) -> NDArray[_IntegerT]: ...
28252824
@overload
2826-
def __xor__(self: NDArray[object_], rhs: object, /) -> NDArray[object_]: ...
2827-
@overload
2828-
def __xor__(self, rhs: _ArrayLikeObject_co, /) -> NDArray[object_]: ...
2825+
def __xor__(self: NDArray[object_], x: object, /) -> NDArray[object_]: ...
28292826

28302827
#
28312828
@overload
2832-
def __rxor__(self: NDArray[bool_], lhs: _nt.ToBool_nd, /) -> NDArray[bool_]: ...
2833-
@overload
2834-
def __rxor__(self: NDArray[unsignedinteger], lhs: _nt.CoUInt64_nd, /) -> NDArray[unsignedinteger]: ...
2829+
def __rxor__(self: NDArray[bool_], x: _PyIntND, /) -> NDArray[intp]: ...
28352830
@overload
2836-
def __rxor__(self: NDArray[signedinteger], lhs: _nt.CoInt64_nd, /) -> NDArray[signedinteger]: ...
2831+
def __rxor__(self: NDArray[_IntegerT], x: _PyCoIntND, /) -> NDArray[_IntegerT]: ...
28372832
@overload
2838-
def __rxor__(self: NDArray[integer], lhs: _nt.CoInt64_nd, /) -> NDArray[integer]: ...
2833+
def __rxor__(self: NDArray[_CoIntegerT], x: _nt.Casts[_CoIntegerT] | _PyBoolND, /) -> NDArray[_CoIntegerT]: ...
28392834
@overload
2840-
def __rxor__(self: NDArray[object_], lhs: object, /) -> NDArray[object_]: ...
2835+
def __rxor__(self: NDArray[_CoIntegerT], x: _nt.CastsWith[_CoIntegerT, _IntegerT], /) -> NDArray[_IntegerT]: ...
28412836
@overload
2842-
def __rxor__(self, lhs: _ArrayLikeObject_co, /) -> NDArray[object_]: ...
2837+
def __rxor__(self: NDArray[object_], x: object, /) -> NDArray[object_]: ...
28432838

28442839
#
28452840
@overload # type: ignore[misc]
2846-
def __ixor__(self: NDArray[bool_], rhs: _nt.ToBool_nd, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
2847-
@overload
2848-
def __ixor__(self: NDArray[unsignedinteger], rhs: _nt.CoUInt64_nd, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
2841+
def __ixor__(self: NDArray[bool_], x: _nt.ToBool_nd, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
28492842
@overload
2850-
def __ixor__(self: NDArray[integer], rhs: _nt.CoInt64_nd, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
2843+
def __ixor__(
2844+
self: NDArray[_IntegerT], x: _nt.Casts[_IntegerT] | _PyCoIntND, /
2845+
) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
28512846
@overload
2852-
def __ixor__(self: NDArray[object_], rhs: object, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
2847+
def __ixor__(self: NDArray[object_], x: object, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
28532848

28542849
#
28552850
@overload
2856-
def __or__(self: NDArray[bool_], rhs: _nt.ToBool_nd, /) -> NDArray[bool_]: ...
2851+
def __or__(self: NDArray[bool_], x: _PyIntND, /) -> NDArray[intp]: ...
28572852
@overload
2858-
def __or__(self: NDArray[unsignedinteger], rhs: _nt.CoUInt64_nd, /) -> NDArray[unsignedinteger]: ...
2853+
def __or__(self: NDArray[_IntegerT], x: _PyCoIntND, /) -> NDArray[_IntegerT]: ...
28592854
@overload
2860-
def __or__(self: NDArray[signedinteger], rhs: _nt.CoInt64_nd, /) -> NDArray[signedinteger]: ...
2855+
def __or__(self: NDArray[_CoIntegerT], x: _nt.Casts[_CoIntegerT] | _PyBoolND, /) -> NDArray[_CoIntegerT]: ...
28612856
@overload
2862-
def __or__(self: NDArray[integer], rhs: _nt.CoInt64_nd, /) -> NDArray[integer]: ...
2857+
def __or__(self: NDArray[_CoIntegerT], x: _nt.CastsWith[_CoIntegerT, _IntegerT], /) -> NDArray[_IntegerT]: ...
28632858
@overload
2864-
def __or__(self: NDArray[object_], rhs: object, /) -> NDArray[object_]: ...
2865-
@overload
2866-
def __or__(self, rhs: _ArrayLikeObject_co, /) -> NDArray[object_]: ...
2859+
def __or__(self: NDArray[object_], x: object, /) -> NDArray[object_]: ...
28672860

28682861
#
28692862
@overload
2870-
def __ror__(self: NDArray[bool_], lhs: _nt.ToBool_nd, /) -> NDArray[bool_]: ...
2871-
@overload
2872-
def __ror__(self: NDArray[unsignedinteger], lhs: _nt.CoUInt64_nd, /) -> NDArray[unsignedinteger]: ...
2863+
def __ror__(self: NDArray[bool_], x: _PyIntND, /) -> NDArray[intp]: ...
28732864
@overload
2874-
def __ror__(self: NDArray[signedinteger], lhs: _nt.CoInt64_nd, /) -> NDArray[signedinteger]: ...
2865+
def __ror__(self: NDArray[_IntegerT], x: _PyCoIntND, /) -> NDArray[_IntegerT]: ...
28752866
@overload
2876-
def __ror__(self: NDArray[integer], lhs: _nt.CoInt64_nd, /) -> NDArray[integer]: ...
2867+
def __ror__(self: NDArray[_CoIntegerT], x: _nt.Casts[_CoIntegerT] | _PyBoolND, /) -> NDArray[_CoIntegerT]: ...
28772868
@overload
2878-
def __ror__(self: NDArray[object_], lhs: object, /) -> NDArray[object_]: ...
2869+
def __ror__(self: NDArray[_CoIntegerT], x: _nt.CastsWith[_CoIntegerT, _IntegerT], /) -> NDArray[_IntegerT]: ...
28792870
@overload
2880-
def __ror__(self, lhs: _ArrayLikeObject_co, /) -> NDArray[object_]: ...
2871+
def __ror__(self: NDArray[object_], x: object, /) -> NDArray[object_]: ...
28812872

28822873
#
28832874
@overload # type: ignore[misc]
2884-
def __ior__(self: NDArray[bool_], rhs: _nt.ToBool_nd, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
2885-
@overload
2886-
def __ior__(self: NDArray[unsignedinteger], rhs: _nt.CoUInt64_nd, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
2875+
def __ior__(self: NDArray[bool_], x: _nt.ToBool_nd, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
28872876
@overload
2888-
def __ior__(self: NDArray[integer], rhs: _nt.CoInt64_nd, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
2877+
def __ior__(
2878+
self: NDArray[_IntegerT], x: _nt.Casts[_IntegerT] | _PyCoIntND, /
2879+
) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
28892880
@overload
2890-
def __ior__(self: NDArray[object_], rhs: object, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
2881+
def __ior__(self: NDArray[object_], x: object, /) -> ndarray[_ShapeT_co, _DTypeT_co]: ...
28912882

28922883
#
28932884
def __dlpack__(

0 commit comments

Comments
 (0)