diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2021-02-05 11:41:51 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-05 11:41:51 -0700 |
commit | 43598128a0f452f2d016bcdb9f52d2ca8b148b0c (patch) | |
tree | c24928adbe58e0cbcfb1804df50b3c6246fea05e /numpy | |
parent | 6373ded2ed1403cc3ec40dc5d919b316a1b58e44 (diff) | |
parent | b3e44cc6e5ba721670c245bc620a0bd7e2913630 (diff) | |
download | numpy-43598128a0f452f2d016bcdb9f52d2ca8b148b0c.tar.gz |
Merge pull request #18323 from BvB93/comparison4
ENH: Add dtype-support to the ufunc-based `ndarray` magic methods 3/4
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/__init__.pyi | 344 | ||||
-rw-r--r-- | numpy/typing/_callable.py | 2 | ||||
-rw-r--r-- | numpy/typing/tests/data/fail/arithmetic.py | 37 | ||||
-rw-r--r-- | numpy/typing/tests/data/pass/arithmetic.py | 100 | ||||
-rw-r--r-- | numpy/typing/tests/data/reveal/arithmetic.py | 102 | ||||
-rw-r--r-- | numpy/typing/tests/test_typing.py | 3 |
6 files changed, 571 insertions, 17 deletions
diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi index b29ba38da..5f731683d 100644 --- a/numpy/__init__.pyi +++ b/numpy/__init__.pyi @@ -11,6 +11,7 @@ from numpy.typing import ( ArrayLike, _ArrayND, _ArrayOrScalar, + _SupportsArray, _NestedSequence, _RecursiveSequence, _ArrayLikeBool_co, @@ -1839,22 +1840,333 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]): other: _RecursiveSequence, ) -> Any: ... - def __floordiv__(self, other: ArrayLike) -> Any: ... - def __rfloordiv__(self, other: ArrayLike) -> Any: ... - def __pow__(self, other: ArrayLike) -> Any: ... - def __rpow__(self, other: ArrayLike) -> Any: ... - def __truediv__(self, other: ArrayLike) -> Any: ... - def __rtruediv__(self, other: ArrayLike) -> Any: ... - def __lshift__(self, other: ArrayLike) -> Any: ... - def __rlshift__(self, other: ArrayLike) -> Any: ... - def __rshift__(self, other: ArrayLike) -> Any: ... - def __rrshift__(self, other: ArrayLike) -> Any: ... - def __and__(self, other: ArrayLike) -> Any: ... - def __rand__(self, other: ArrayLike) -> Any: ... - def __xor__(self, other: ArrayLike) -> Any: ... - def __rxor__(self, other: ArrayLike) -> Any: ... - def __or__(self, other: ArrayLike) -> Any: ... - def __ror__(self, other: ArrayLike) -> Any: ... + @overload + def __floordiv__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ... + @overload + def __floordiv__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayOrScalar[int8]: ... # type: ignore[misc] + @overload + def __floordiv__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayOrScalar[unsignedinteger[Any]]: ... # type: ignore[misc] + @overload + def __floordiv__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayOrScalar[signedinteger[Any]]: ... # type: ignore[misc] + @overload + def __floordiv__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _ArrayOrScalar[floating[Any]]: ... # type: ignore[misc] + @overload + def __floordiv__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> _ArrayOrScalar[complexfloating[Any, Any]]: ... # type: ignore[misc] + @overload + def __floordiv__(self: _ArrayND[timedelta64], other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> _ArrayOrScalar[int64]: ... + @overload + def __floordiv__(self: _ArrayND[timedelta64], other: _ArrayLikeBool_co) -> NoReturn: ... + @overload + def __floordiv__(self: _ArrayND[timedelta64], other: _ArrayLikeFloat_co) -> _ArrayOrScalar[timedelta64]: ... + @overload + def __floordiv__(self: _ArrayND[object_], other: Any) -> Any: ... + @overload + def __floordiv__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ... + @overload + def __floordiv__( + self: _ArrayND[Union[bool_, number[Any], timedelta64]], + other: _RecursiveSequence, + ) -> Any: ... + + @overload + def __rfloordiv__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ... + @overload + def __rfloordiv__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayOrScalar[int8]: ... # type: ignore[misc] + @overload + def __rfloordiv__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayOrScalar[unsignedinteger[Any]]: ... # type: ignore[misc] + @overload + def __rfloordiv__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayOrScalar[signedinteger[Any]]: ... # type: ignore[misc] + @overload + def __rfloordiv__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _ArrayOrScalar[floating[Any]]: ... # type: ignore[misc] + @overload + def __rfloordiv__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> _ArrayOrScalar[complexfloating[Any, Any]]: ... # type: ignore[misc] + @overload + def __rfloordiv__(self: _ArrayND[timedelta64], other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> _ArrayOrScalar[int64]: ... + @overload + def __rfloordiv__(self: _ArrayND[bool_], other: _ArrayLikeTD64_co) -> NoReturn: ... + @overload + def __rfloordiv__(self: _ArrayFloat_co, other: _ArrayLikeTD64_co) -> _ArrayOrScalar[timedelta64]: ... + @overload + def __rfloordiv__(self: _ArrayND[object_], other: Any) -> Any: ... + @overload + def __rfloordiv__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ... + @overload + def __rfloordiv__( + self: _ArrayND[Union[bool_, number[Any], timedelta64]], + other: _RecursiveSequence, + ) -> Any: ... + + @overload + def __pow__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ... + @overload + def __pow__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayOrScalar[int8]: ... # type: ignore[misc] + @overload + def __pow__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayOrScalar[unsignedinteger[Any]]: ... # type: ignore[misc] + @overload + def __pow__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayOrScalar[signedinteger[Any]]: ... # type: ignore[misc] + @overload + def __pow__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _ArrayOrScalar[floating[Any]]: ... # type: ignore[misc] + @overload + def __pow__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> _ArrayOrScalar[complexfloating[Any, Any]]: ... + @overload + def __pow__(self: _ArrayND[object_], other: Any) -> Any: ... + @overload + def __pow__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ... + @overload + def __pow__( + self: _ArrayND[Union[bool_, number[Any]]], + other: _RecursiveSequence, + ) -> Any: ... + + @overload + def __rpow__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ... + @overload + def __rpow__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayOrScalar[int8]: ... # type: ignore[misc] + @overload + def __rpow__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayOrScalar[unsignedinteger[Any]]: ... # type: ignore[misc] + @overload + def __rpow__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayOrScalar[signedinteger[Any]]: ... # type: ignore[misc] + @overload + def __rpow__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _ArrayOrScalar[floating[Any]]: ... # type: ignore[misc] + @overload + def __rpow__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> _ArrayOrScalar[complexfloating[Any, Any]]: ... + @overload + def __rpow__(self: _ArrayND[object_], other: Any) -> Any: ... + @overload + def __rpow__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ... + @overload + def __rpow__( + self: _ArrayND[Union[bool_, number[Any]]], + other: _RecursiveSequence, + ) -> Any: ... + + @overload + def __truediv__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ... + @overload + def __truediv__(self: _ArrayInt_co, other: _ArrayInt_co) -> _ArrayOrScalar[float64]: ... # type: ignore[misc] + @overload + def __truediv__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _ArrayOrScalar[floating[Any]]: ... # type: ignore[misc] + @overload + def __truediv__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> _ArrayOrScalar[complexfloating[Any, Any]]: ... # type: ignore[misc] + @overload + def __truediv__(self: _ArrayND[timedelta64], other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> _ArrayOrScalar[float64]: ... + @overload + def __truediv__(self: _ArrayND[timedelta64], other: _ArrayLikeBool_co) -> NoReturn: ... + @overload + def __truediv__(self: _ArrayND[timedelta64], other: _ArrayLikeFloat_co) -> _ArrayOrScalar[timedelta64]: ... + @overload + def __truediv__(self: _ArrayND[object_], other: Any) -> Any: ... + @overload + def __truediv__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ... + @overload + def __truediv__( + self: _ArrayND[Union[bool_, number[Any], timedelta64]], + other: _RecursiveSequence, + ) -> Any: ... + + @overload + def __rtruediv__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ... + @overload + def __rtruediv__(self: _ArrayInt_co, other: _ArrayInt_co) -> _ArrayOrScalar[float64]: ... # type: ignore[misc] + @overload + def __rtruediv__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _ArrayOrScalar[floating[Any]]: ... # type: ignore[misc] + @overload + def __rtruediv__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> _ArrayOrScalar[complexfloating[Any, Any]]: ... # type: ignore[misc] + @overload + def __rtruediv__(self: _ArrayND[timedelta64], other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> _ArrayOrScalar[float64]: ... + @overload + def __rtruediv__(self: _ArrayND[bool_], other: _ArrayLikeTD64_co) -> NoReturn: ... + @overload + def __rtruediv__(self: _ArrayFloat_co, other: _ArrayLikeTD64_co) -> _ArrayOrScalar[timedelta64]: ... + @overload + def __rtruediv__(self: _ArrayND[object_], other: Any) -> Any: ... + @overload + def __rtruediv__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ... + @overload + def __rtruediv__( + self: _ArrayND[Union[bool_, number[Any], timedelta64]], + other: _RecursiveSequence, + ) -> Any: ... + + @overload + def __lshift__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ... + @overload + def __lshift__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayOrScalar[int8]: ... # type: ignore[misc] + @overload + def __lshift__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayOrScalar[unsignedinteger[Any]]: ... # type: ignore[misc] + @overload + def __lshift__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayOrScalar[signedinteger[Any]]: ... + @overload + def __lshift__(self: _ArrayND[object_], other: Any) -> Any: ... + @overload + def __lshift__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ... + @overload + def __lshift__( + self: _ArrayND[Union[bool_, integer[Any]]], + other: _RecursiveSequence, + ) -> Any: ... + + @overload + def __rlshift__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ... + @overload + def __rlshift__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayOrScalar[int8]: ... # type: ignore[misc] + @overload + def __rlshift__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayOrScalar[unsignedinteger[Any]]: ... # type: ignore[misc] + @overload + def __rlshift__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayOrScalar[signedinteger[Any]]: ... + @overload + def __rlshift__(self: _ArrayND[object_], other: Any) -> Any: ... + @overload + def __rlshift__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ... + @overload + def __rlshift__( + self: _ArrayND[Union[bool_, integer[Any]]], + other: _RecursiveSequence, + ) -> Any: ... + + @overload + def __rshift__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ... + @overload + def __rshift__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayOrScalar[int8]: ... # type: ignore[misc] + @overload + def __rshift__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayOrScalar[unsignedinteger[Any]]: ... # type: ignore[misc] + @overload + def __rshift__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayOrScalar[signedinteger[Any]]: ... + @overload + def __rshift__(self: _ArrayND[object_], other: Any) -> Any: ... + @overload + def __rshift__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ... + @overload + def __rshift__( + self: _ArrayND[Union[bool_, integer[Any]]], + other: _RecursiveSequence, + ) -> Any: ... + + @overload + def __rrshift__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ... + @overload + def __rrshift__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayOrScalar[int8]: ... # type: ignore[misc] + @overload + def __rrshift__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayOrScalar[unsignedinteger[Any]]: ... # type: ignore[misc] + @overload + def __rrshift__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayOrScalar[signedinteger[Any]]: ... + @overload + def __rrshift__(self: _ArrayND[object_], other: Any) -> Any: ... + @overload + def __rrshift__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ... + @overload + def __rrshift__( + self: _ArrayND[Union[bool_, integer[Any]]], + other: _RecursiveSequence, + ) -> Any: ... + + @overload + def __and__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ... + @overload + def __and__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayOrScalar[bool_]: ... # type: ignore[misc] + @overload + def __and__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayOrScalar[unsignedinteger[Any]]: ... # type: ignore[misc] + @overload + def __and__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayOrScalar[signedinteger[Any]]: ... + @overload + def __and__(self: _ArrayND[object_], other: Any) -> Any: ... + @overload + def __and__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ... + @overload + def __and__( + self: _ArrayND[Union[bool_, integer[Any]]], + other: _RecursiveSequence, + ) -> Any: ... + + @overload + def __rand__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ... + @overload + def __rand__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayOrScalar[bool_]: ... # type: ignore[misc] + @overload + def __rand__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayOrScalar[unsignedinteger[Any]]: ... # type: ignore[misc] + @overload + def __rand__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayOrScalar[signedinteger[Any]]: ... + @overload + def __rand__(self: _ArrayND[object_], other: Any) -> Any: ... + @overload + def __rand__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ... + @overload + def __rand__( + self: _ArrayND[Union[bool_, integer[Any]]], + other: _RecursiveSequence, + ) -> Any: ... + + @overload + def __xor__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ... + @overload + def __xor__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayOrScalar[bool_]: ... # type: ignore[misc] + @overload + def __xor__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayOrScalar[unsignedinteger[Any]]: ... # type: ignore[misc] + @overload + def __xor__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayOrScalar[signedinteger[Any]]: ... + @overload + def __xor__(self: _ArrayND[object_], other: Any) -> Any: ... + @overload + def __xor__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ... + @overload + def __xor__( + self: _ArrayND[Union[bool_, integer[Any]]], + other: _RecursiveSequence, + ) -> Any: ... + + @overload + def __rxor__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ... + @overload + def __rxor__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayOrScalar[bool_]: ... # type: ignore[misc] + @overload + def __rxor__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayOrScalar[unsignedinteger[Any]]: ... # type: ignore[misc] + @overload + def __rxor__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayOrScalar[signedinteger[Any]]: ... + @overload + def __rxor__(self: _ArrayND[object_], other: Any) -> Any: ... + @overload + def __rxor__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ... + @overload + def __rxor__( + self: _ArrayND[Union[bool_, integer[Any]]], + other: _RecursiveSequence, + ) -> Any: ... + + @overload + def __or__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ... + @overload + def __or__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayOrScalar[bool_]: ... # type: ignore[misc] + @overload + def __or__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayOrScalar[unsignedinteger[Any]]: ... # type: ignore[misc] + @overload + def __or__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayOrScalar[signedinteger[Any]]: ... + @overload + def __or__(self: _ArrayND[object_], other: Any) -> Any: ... + @overload + def __or__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ... + @overload + def __or__( + self: _ArrayND[Union[bool_, integer[Any]]], + other: _RecursiveSequence, + ) -> Any: ... + + @overload + def __ror__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ... + @overload + def __ror__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayOrScalar[bool_]: ... # type: ignore[misc] + @overload + def __ror__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayOrScalar[unsignedinteger[Any]]: ... # type: ignore[misc] + @overload + def __ror__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayOrScalar[signedinteger[Any]]: ... + @overload + def __ror__(self: _ArrayND[object_], other: Any) -> Any: ... + @overload + def __ror__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ... + @overload + def __ror__( + self: _ArrayND[Union[bool_, integer[Any]]], + other: _RecursiveSequence, + ) -> Any: ... # `np.generic` does not support inplace operations def __iadd__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ... diff --git a/numpy/typing/_callable.py b/numpy/typing/_callable.py index 1591ca144..0e34cd799 100644 --- a/numpy/typing/_callable.py +++ b/numpy/typing/_callable.py @@ -143,6 +143,8 @@ if TYPE_CHECKING or HAVE_PROTOCOL: @overload def __call__(self, __other: timedelta64) -> _NumberType_co: ... @overload + def __call__(self, __other: _BoolLike_co) -> NoReturn: ... + @overload def __call__(self, __other: _FloatLike_co) -> timedelta64: ... class _IntTrueDiv(Protocol[_NBit1]): diff --git a/numpy/typing/tests/data/fail/arithmetic.py b/numpy/typing/tests/data/fail/arithmetic.py index bad7040b9..1ca8a7b70 100644 --- a/numpy/typing/tests/data/fail/arithmetic.py +++ b/numpy/typing/tests/data/fail/arithmetic.py @@ -6,17 +6,25 @@ dt = np.datetime64(0, "D") td = np.timedelta64(0, "D") AR_b: np.ndarray[Any, np.dtype[np.bool_]] +AR_u: np.ndarray[Any, np.dtype[np.uint32]] +AR_i: np.ndarray[Any, np.dtype[np.int64]] AR_f: np.ndarray[Any, np.dtype[np.float64]] AR_c: np.ndarray[Any, np.dtype[np.complex128]] AR_m: np.ndarray[Any, np.dtype[np.timedelta64]] AR_M: np.ndarray[Any, np.dtype[np.datetime64]] +ANY: Any + AR_LIKE_b: List[bool] +AR_LIKE_u: List[np.uint32] +AR_LIKE_i: List[int] AR_LIKE_f: List[float] AR_LIKE_c: List[complex] AR_LIKE_m: List[np.timedelta64] AR_LIKE_M: List[np.datetime64] +# Array subtraction + # NOTE: mypys `NoReturn` errors are, unfortunately, not that great _1 = AR_b - AR_LIKE_b # E: Need type annotation _2 = AR_LIKE_b - AR_b # E: Need type annotation @@ -34,6 +42,35 @@ AR_M - AR_LIKE_c # E: Unsupported operand types AR_m - AR_LIKE_M # E: Unsupported operand types AR_LIKE_m - AR_M # E: Unsupported operand types +# array floor division + +AR_M // AR_LIKE_b # E: Unsupported operand types +AR_M // AR_LIKE_u # E: Unsupported operand types +AR_M // AR_LIKE_i # E: Unsupported operand types +AR_M // AR_LIKE_f # E: Unsupported operand types +AR_M // AR_LIKE_c # E: Unsupported operand types +AR_M // AR_LIKE_m # E: Unsupported operand types +AR_M // AR_LIKE_M # E: Unsupported operand types + +AR_b // AR_LIKE_M # E: Unsupported operand types +AR_u // AR_LIKE_M # E: Unsupported operand types +AR_i // AR_LIKE_M # E: Unsupported operand types +AR_f // AR_LIKE_M # E: Unsupported operand types +AR_c // AR_LIKE_M # E: Unsupported operand types +AR_m // AR_LIKE_M # E: Unsupported operand types +AR_M // AR_LIKE_M # E: Unsupported operand types + +_3 = AR_m // AR_LIKE_b # E: Need type annotation +AR_m // AR_LIKE_c # E: Unsupported operand types + +AR_b // AR_LIKE_m # E: Unsupported operand types +AR_u // AR_LIKE_m # E: Unsupported operand types +AR_i // AR_LIKE_m # E: Unsupported operand types +AR_f // AR_LIKE_m # E: Unsupported operand types +AR_c // AR_LIKE_m # E: Unsupported operand types + +# Scalars + b_ - b_ # E: No overload variant dt + dt # E: Unsupported operand types diff --git a/numpy/typing/tests/data/pass/arithmetic.py b/numpy/typing/tests/data/pass/arithmetic.py index 4840d1fab..86e7a92a8 100644 --- a/numpy/typing/tests/data/pass/arithmetic.py +++ b/numpy/typing/tests/data/pass/arithmetic.py @@ -36,6 +36,12 @@ class Object: def __rsub__(self, value: Any) -> Object: return self + def __floordiv__(self, value: Any) -> Object: + return self + + def __rfloordiv__(self, value: Any) -> Object: + return self + AR_b: np.ndarray[Any, np.dtype[np.bool_]] = np.array([True]) AR_u: np.ndarray[Any, np.dtype[np.uint32]] = np.array([1], dtype=np.uint32) @@ -167,6 +173,100 @@ AR_LIKE_f - AR_O AR_LIKE_c - AR_O AR_LIKE_O - AR_O +# Array floor division + +AR_b // AR_LIKE_b +AR_b // AR_LIKE_u +AR_b // AR_LIKE_i +AR_b // AR_LIKE_f +AR_b // AR_LIKE_c +AR_b // AR_LIKE_O + +AR_LIKE_b // AR_b +AR_LIKE_u // AR_b +AR_LIKE_i // AR_b +AR_LIKE_f // AR_b +AR_LIKE_c // AR_b +AR_LIKE_O // AR_b + +AR_u // AR_LIKE_b +AR_u // AR_LIKE_u +AR_u // AR_LIKE_i +AR_u // AR_LIKE_f +AR_u // AR_LIKE_c +AR_u // AR_LIKE_O + +AR_LIKE_b // AR_u +AR_LIKE_u // AR_u +AR_LIKE_i // AR_u +AR_LIKE_f // AR_u +AR_LIKE_c // AR_u +AR_LIKE_m // AR_u +AR_LIKE_O // AR_u + +AR_i // AR_LIKE_b +AR_i // AR_LIKE_u +AR_i // AR_LIKE_i +AR_i // AR_LIKE_f +AR_i // AR_LIKE_c +AR_i // AR_LIKE_O + +AR_LIKE_b // AR_i +AR_LIKE_u // AR_i +AR_LIKE_i // AR_i +AR_LIKE_f // AR_i +AR_LIKE_c // AR_i +AR_LIKE_m // AR_i +AR_LIKE_O // AR_i + +AR_f // AR_LIKE_b +AR_f // AR_LIKE_u +AR_f // AR_LIKE_i +AR_f // AR_LIKE_f +AR_f // AR_LIKE_c +AR_f // AR_LIKE_O + +AR_LIKE_b // AR_f +AR_LIKE_u // AR_f +AR_LIKE_i // AR_f +AR_LIKE_f // AR_f +AR_LIKE_c // AR_f +AR_LIKE_m // AR_f +AR_LIKE_O // AR_f + +AR_c // AR_LIKE_b +AR_c // AR_LIKE_u +AR_c // AR_LIKE_i +AR_c // AR_LIKE_f +AR_c // AR_LIKE_c + +AR_LIKE_b // AR_c +AR_LIKE_u // AR_c +AR_LIKE_i // AR_c +AR_LIKE_f // AR_c +AR_LIKE_c // AR_c +AR_LIKE_O // AR_c + +AR_m // AR_LIKE_u +AR_m // AR_LIKE_i +AR_m // AR_LIKE_f +AR_m // AR_LIKE_m + +AR_LIKE_m // AR_m + +AR_O // AR_LIKE_b +AR_O // AR_LIKE_u +AR_O // AR_LIKE_i +AR_O // AR_LIKE_f +AR_O // AR_LIKE_c +AR_O // AR_LIKE_O + +AR_LIKE_b // AR_O +AR_LIKE_u // AR_O +AR_LIKE_i // AR_O +AR_LIKE_f // AR_O +AR_LIKE_O // AR_O + # unary ops -c16 diff --git a/numpy/typing/tests/data/reveal/arithmetic.py b/numpy/typing/tests/data/reveal/arithmetic.py index 1a0f595c5..b45330910 100644 --- a/numpy/typing/tests/data/reveal/arithmetic.py +++ b/numpy/typing/tests/data/reveal/arithmetic.py @@ -159,6 +159,108 @@ reveal_type(AR_LIKE_m - AR_O) # E: Any reveal_type(AR_LIKE_M - AR_O) # E: Any reveal_type(AR_LIKE_O - AR_O) # E: Any +# Array floor division + +reveal_type(AR_b // AR_LIKE_b) # E: Union[{int8}, numpy.ndarray[Any, numpy.dtype[{int8}]]] +reveal_type(AR_b // AR_LIKE_u) # E: Union[numpy.unsignedinteger[Any], numpy.ndarray[Any, numpy.dtype[numpy.unsignedinteger[Any]]]] +reveal_type(AR_b // AR_LIKE_i) # E: Union[numpy.signedinteger[Any], numpy.ndarray[Any, numpy.dtype[numpy.signedinteger[Any]]]] +reveal_type(AR_b // AR_LIKE_f) # E: Union[numpy.floating[Any], numpy.ndarray[Any, numpy.dtype[numpy.floating[Any]]]] +reveal_type(AR_b // AR_LIKE_c) # E: Union[numpy.complexfloating[Any, Any], numpy.ndarray[Any, numpy.dtype[numpy.complexfloating[Any, Any]]]] +reveal_type(AR_b // AR_LIKE_O) # E: Any + +reveal_type(AR_LIKE_b // AR_b) # E: Union[{int8}, numpy.ndarray[Any, numpy.dtype[{int8}]]] +reveal_type(AR_LIKE_u // AR_b) # E: Union[numpy.unsignedinteger[Any], numpy.ndarray[Any, numpy.dtype[numpy.unsignedinteger[Any]]]] +reveal_type(AR_LIKE_i // AR_b) # E: Union[numpy.signedinteger[Any], numpy.ndarray[Any, numpy.dtype[numpy.signedinteger[Any]]]] +reveal_type(AR_LIKE_f // AR_b) # E: Union[numpy.floating[Any], numpy.ndarray[Any, numpy.dtype[numpy.floating[Any]]]] +reveal_type(AR_LIKE_c // AR_b) # E: Union[numpy.complexfloating[Any, Any], numpy.ndarray[Any, numpy.dtype[numpy.complexfloating[Any, Any]]]] +reveal_type(AR_LIKE_O // AR_b) # E: Any + +reveal_type(AR_u // AR_LIKE_b) # E: Union[numpy.unsignedinteger[Any], numpy.ndarray[Any, numpy.dtype[numpy.unsignedinteger[Any]]]] +reveal_type(AR_u // AR_LIKE_u) # E: Union[numpy.unsignedinteger[Any], numpy.ndarray[Any, numpy.dtype[numpy.unsignedinteger[Any]]]] +reveal_type(AR_u // AR_LIKE_i) # E: Union[numpy.signedinteger[Any], numpy.ndarray[Any, numpy.dtype[numpy.signedinteger[Any]]]] +reveal_type(AR_u // AR_LIKE_f) # E: Union[numpy.floating[Any], numpy.ndarray[Any, numpy.dtype[numpy.floating[Any]]]] +reveal_type(AR_u // AR_LIKE_c) # E: Union[numpy.complexfloating[Any, Any], numpy.ndarray[Any, numpy.dtype[numpy.complexfloating[Any, Any]]]] +reveal_type(AR_u // AR_LIKE_O) # E: Any + +reveal_type(AR_LIKE_b // AR_u) # E: Union[numpy.unsignedinteger[Any], numpy.ndarray[Any, numpy.dtype[numpy.unsignedinteger[Any]]]] +reveal_type(AR_LIKE_u // AR_u) # E: Union[numpy.unsignedinteger[Any], numpy.ndarray[Any, numpy.dtype[numpy.unsignedinteger[Any]]]] +reveal_type(AR_LIKE_i // AR_u) # E: Union[numpy.signedinteger[Any], numpy.ndarray[Any, numpy.dtype[numpy.signedinteger[Any]]]] +reveal_type(AR_LIKE_f // AR_u) # E: Union[numpy.floating[Any], numpy.ndarray[Any, numpy.dtype[numpy.floating[Any]]]] +reveal_type(AR_LIKE_c // AR_u) # E: Union[numpy.complexfloating[Any, Any], numpy.ndarray[Any, numpy.dtype[numpy.complexfloating[Any, Any]]]] +reveal_type(AR_LIKE_m // AR_u) # E: Union[numpy.timedelta64, numpy.ndarray[Any, numpy.dtype[numpy.timedelta64]]] +reveal_type(AR_LIKE_O // AR_u) # E: Any + +reveal_type(AR_i // AR_LIKE_b) # E: Union[numpy.signedinteger[Any], numpy.ndarray[Any, numpy.dtype[numpy.signedinteger[Any]]]] +reveal_type(AR_i // AR_LIKE_u) # E: Union[numpy.signedinteger[Any], numpy.ndarray[Any, numpy.dtype[numpy.signedinteger[Any]]]] +reveal_type(AR_i // AR_LIKE_i) # E: Union[numpy.signedinteger[Any], numpy.ndarray[Any, numpy.dtype[numpy.signedinteger[Any]]]] +reveal_type(AR_i // AR_LIKE_f) # E: Union[numpy.floating[Any], numpy.ndarray[Any, numpy.dtype[numpy.floating[Any]]]] +reveal_type(AR_i // AR_LIKE_c) # E: Union[numpy.complexfloating[Any, Any], numpy.ndarray[Any, numpy.dtype[numpy.complexfloating[Any, Any]]]] +reveal_type(AR_i // AR_LIKE_O) # E: Any + +reveal_type(AR_LIKE_b // AR_i) # E: Union[numpy.signedinteger[Any], numpy.ndarray[Any, numpy.dtype[numpy.signedinteger[Any]]]] +reveal_type(AR_LIKE_u // AR_i) # E: Union[numpy.signedinteger[Any], numpy.ndarray[Any, numpy.dtype[numpy.signedinteger[Any]]]] +reveal_type(AR_LIKE_i // AR_i) # E: Union[numpy.signedinteger[Any], numpy.ndarray[Any, numpy.dtype[numpy.signedinteger[Any]]]] +reveal_type(AR_LIKE_f // AR_i) # E: Union[numpy.floating[Any], numpy.ndarray[Any, numpy.dtype[numpy.floating[Any]]]] +reveal_type(AR_LIKE_c // AR_i) # E: Union[numpy.complexfloating[Any, Any], numpy.ndarray[Any, numpy.dtype[numpy.complexfloating[Any, Any]]]] +reveal_type(AR_LIKE_m // AR_i) # E: Union[numpy.timedelta64, numpy.ndarray[Any, numpy.dtype[numpy.timedelta64]]] +reveal_type(AR_LIKE_O // AR_i) # E: Any + +reveal_type(AR_f // AR_LIKE_b) # E: Union[numpy.floating[Any], numpy.ndarray[Any, numpy.dtype[numpy.floating[Any]]]] +reveal_type(AR_f // AR_LIKE_u) # E: Union[numpy.floating[Any], numpy.ndarray[Any, numpy.dtype[numpy.floating[Any]]]] +reveal_type(AR_f // AR_LIKE_i) # E: Union[numpy.floating[Any], numpy.ndarray[Any, numpy.dtype[numpy.floating[Any]]]] +reveal_type(AR_f // AR_LIKE_f) # E: Union[numpy.floating[Any], numpy.ndarray[Any, numpy.dtype[numpy.floating[Any]]]] +reveal_type(AR_f // AR_LIKE_c) # E: Union[numpy.complexfloating[Any, Any], numpy.ndarray[Any, numpy.dtype[numpy.complexfloating[Any, Any]]]] +reveal_type(AR_f // AR_LIKE_O) # E: Any + +reveal_type(AR_LIKE_b // AR_f) # E: Union[numpy.floating[Any], numpy.ndarray[Any, numpy.dtype[numpy.floating[Any]]]] +reveal_type(AR_LIKE_u // AR_f) # E: Union[numpy.floating[Any], numpy.ndarray[Any, numpy.dtype[numpy.floating[Any]]]] +reveal_type(AR_LIKE_i // AR_f) # E: Union[numpy.floating[Any], numpy.ndarray[Any, numpy.dtype[numpy.floating[Any]]]] +reveal_type(AR_LIKE_f // AR_f) # E: Union[numpy.floating[Any], numpy.ndarray[Any, numpy.dtype[numpy.floating[Any]]]] +reveal_type(AR_LIKE_c // AR_f) # E: Union[numpy.complexfloating[Any, Any], numpy.ndarray[Any, numpy.dtype[numpy.complexfloating[Any, Any]]]] +reveal_type(AR_LIKE_m // AR_f) # E: Union[numpy.timedelta64, numpy.ndarray[Any, numpy.dtype[numpy.timedelta64]]] +reveal_type(AR_LIKE_O // AR_f) # E: Any + +reveal_type(AR_c // AR_LIKE_b) # E: Union[numpy.complexfloating[Any, Any], numpy.ndarray[Any, numpy.dtype[numpy.complexfloating[Any, Any]]]] +reveal_type(AR_c // AR_LIKE_u) # E: Union[numpy.complexfloating[Any, Any], numpy.ndarray[Any, numpy.dtype[numpy.complexfloating[Any, Any]]]] +reveal_type(AR_c // AR_LIKE_i) # E: Union[numpy.complexfloating[Any, Any], numpy.ndarray[Any, numpy.dtype[numpy.complexfloating[Any, Any]]]] +reveal_type(AR_c // AR_LIKE_f) # E: Union[numpy.complexfloating[Any, Any], numpy.ndarray[Any, numpy.dtype[numpy.complexfloating[Any, Any]]]] +reveal_type(AR_c // AR_LIKE_c) # E: Union[numpy.complexfloating[Any, Any], numpy.ndarray[Any, numpy.dtype[numpy.complexfloating[Any, Any]]]] +reveal_type(AR_c // AR_LIKE_O) # E: Any + +reveal_type(AR_LIKE_b // AR_c) # E: Union[numpy.complexfloating[Any, Any], numpy.ndarray[Any, numpy.dtype[numpy.complexfloating[Any, Any]]]] +reveal_type(AR_LIKE_u // AR_c) # E: Union[numpy.complexfloating[Any, Any], numpy.ndarray[Any, numpy.dtype[numpy.complexfloating[Any, Any]]]] +reveal_type(AR_LIKE_i // AR_c) # E: Union[numpy.complexfloating[Any, Any], numpy.ndarray[Any, numpy.dtype[numpy.complexfloating[Any, Any]]]] +reveal_type(AR_LIKE_f // AR_c) # E: Union[numpy.complexfloating[Any, Any], numpy.ndarray[Any, numpy.dtype[numpy.complexfloating[Any, Any]]]] +reveal_type(AR_LIKE_c // AR_c) # E: Union[numpy.complexfloating[Any, Any], numpy.ndarray[Any, numpy.dtype[numpy.complexfloating[Any, Any]]]] +reveal_type(AR_LIKE_O // AR_c) # E: Any + +reveal_type(AR_m // AR_LIKE_u) # E: Union[numpy.timedelta64, numpy.ndarray[Any, numpy.dtype[numpy.timedelta64]]] +reveal_type(AR_m // AR_LIKE_i) # E: Union[numpy.timedelta64, numpy.ndarray[Any, numpy.dtype[numpy.timedelta64]]] +reveal_type(AR_m // AR_LIKE_f) # E: Union[numpy.timedelta64, numpy.ndarray[Any, numpy.dtype[numpy.timedelta64]]] +reveal_type(AR_m // AR_LIKE_m) # E: Union[{int64}, numpy.ndarray[Any, numpy.dtype[{int64}]]] +reveal_type(AR_m // AR_LIKE_O) # E: Any + +reveal_type(AR_LIKE_m // AR_m) # E: Union[{int64}, numpy.ndarray[Any, numpy.dtype[{int64}]]] +reveal_type(AR_LIKE_O // AR_m) # E: Any + +reveal_type(AR_O // AR_LIKE_b) # E: Any +reveal_type(AR_O // AR_LIKE_u) # E: Any +reveal_type(AR_O // AR_LIKE_i) # E: Any +reveal_type(AR_O // AR_LIKE_f) # E: Any +reveal_type(AR_O // AR_LIKE_c) # E: Any +reveal_type(AR_O // AR_LIKE_m) # E: Any +reveal_type(AR_O // AR_LIKE_M) # E: Any +reveal_type(AR_O // AR_LIKE_O) # E: Any + +reveal_type(AR_LIKE_b // AR_O) # E: Any +reveal_type(AR_LIKE_u // AR_O) # E: Any +reveal_type(AR_LIKE_i // AR_O) # E: Any +reveal_type(AR_LIKE_f // AR_O) # E: Any +reveal_type(AR_LIKE_c // AR_O) # E: Any +reveal_type(AR_LIKE_m // AR_O) # E: Any +reveal_type(AR_LIKE_M // AR_O) # E: Any +reveal_type(AR_LIKE_O // AR_O) # E: Any + # unary ops reveal_type(-c16) # E: {complex128} diff --git a/numpy/typing/tests/test_typing.py b/numpy/typing/tests/test_typing.py index 324312a92..fc42e87b1 100644 --- a/numpy/typing/tests/test_typing.py +++ b/numpy/typing/tests/test_typing.py @@ -89,7 +89,8 @@ def get_test_cases(directory): def test_success(path): # Alias `OUTPUT_MYPY` so that it appears in the local namespace output_mypy = OUTPUT_MYPY - assert path not in output_mypy + if path in output_mypy: + raise AssertionError("\n".join(v for v in output_mypy[path].values())) @pytest.mark.slow |