From 2cc9e2994f14ccfb3cc276db08a9d632621fcb55 Mon Sep 17 00:00:00 2001 From: Bas van Beek Date: Tue, 26 Jan 2021 13:26:15 +0100 Subject: ENH: Add dtype-support to the (ufunc-based) `ndarray` inplace magic methods --- numpy/__init__.pyi | 198 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 186 insertions(+), 12 deletions(-) diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi index dba4176f2..4964dfce2 100644 --- a/numpy/__init__.pyi +++ b/numpy/__init__.pyi @@ -15,6 +15,7 @@ from numpy.typing import ( _SupportsArray, _NestedSequence, _RecursiveSequence, + _SupportsArray, _ArrayLikeBool_co, _ArrayLikeUInt_co, _ArrayLikeInt_co, @@ -2202,18 +2203,191 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]): ) -> Any: ... # `np.generic` does not support inplace operations - def __iadd__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ... - def __isub__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ... - def __imul__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ... - def __itruediv__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ... - def __ifloordiv__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ... - def __ipow__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ... - def __imod__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ... - def __ilshift__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ... - def __irshift__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ... - def __iand__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ... - def __ixor__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ... - def __ior__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ... + @overload # type: ignore[misc] + def __iadd__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ... + @overload + def __iadd__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ... + @overload + def __iadd__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ... + @overload + def __iadd__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ... + @overload + def __iadd__(self: _ArrayND[floating[_NBit1]], other: _ArrayLikeFloat_co) -> _ArrayND[floating[_NBit1]]: ... + @overload + def __iadd__(self: _ArrayND[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[_NBit1, _NBit1]]: ... + @overload + def __iadd__(self: _ArrayND[timedelta64], other: _ArrayLikeTD64_co) -> _ArrayND[timedelta64]: ... + @overload + def __iadd__(self: _ArrayND[datetime64], other: _ArrayLikeTD64_co) -> _ArrayND[datetime64]: ... + @overload + def __iadd__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ... + @overload + def __iadd__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ... + + @overload # type: ignore[misc] + def __isub__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ... + @overload + def __isub__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> NoReturn: ... + @overload + def __isub__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ... + @overload + def __isub__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ... + @overload + def __isub__(self: _ArrayND[floating[_NBit1]], other: _ArrayLikeFloat_co) -> _ArrayND[floating[_NBit1]]: ... + @overload + def __isub__(self: _ArrayND[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[_NBit1, _NBit1]]: ... + @overload + def __isub__(self: _ArrayND[timedelta64], other: _ArrayLikeTD64_co) -> _ArrayND[timedelta64]: ... + @overload + def __isub__(self: _ArrayND[datetime64], other: _ArrayLikeTD64_co) -> _ArrayND[datetime64]: ... + @overload + def __isub__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ... + @overload + def __isub__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ... + + @overload # type: ignore[misc] + def __imul__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ... + @overload + def __imul__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ... + @overload + def __imul__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ... + @overload + def __imul__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ... + @overload + def __imul__(self: _ArrayND[floating[_NBit1]], other: _ArrayLikeFloat_co) -> _ArrayND[floating[_NBit1]]: ... + @overload + def __imul__(self: _ArrayND[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[_NBit1, _NBit1]]: ... + @overload + def __imul__(self: _ArrayND[timedelta64], other: _ArrayLikeFloat_co) -> _ArrayND[timedelta64]: ... + @overload + def __imul__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ... + @overload + def __imul__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ... + + @overload # type: ignore[misc] + def __itruediv__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ... + @overload + def __itruediv__(self: _ArrayND[floating[_NBit1]], other: _ArrayLikeFloat_co) -> _ArrayND[floating[_NBit1]]: ... + @overload + def __itruediv__(self: _ArrayND[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[_NBit1, _NBit1]]: ... + @overload + def __itruediv__(self: _ArrayND[timedelta64], other: _ArrayLikeBool_co) -> NoReturn: ... + @overload + def __itruediv__(self: _ArrayND[timedelta64], other: _ArrayLikeInt_co) -> _ArrayND[timedelta64]: ... + @overload + def __itruediv__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ... + @overload + def __itruediv__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ... + + @overload # type: ignore[misc] + def __ifloordiv__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ... + @overload + def __ifloordiv__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ... + @overload + def __ifloordiv__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ... + @overload + def __ifloordiv__(self: _ArrayND[floating[_NBit1]], other: _ArrayLikeFloat_co) -> _ArrayND[floating[_NBit1]]: ... + @overload + def __ifloordiv__(self: _ArrayND[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[_NBit1, _NBit1]]: ... + @overload + def __ifloordiv__(self: _ArrayND[timedelta64], other: _ArrayLikeBool_co) -> NoReturn: ... + @overload + def __ifloordiv__(self: _ArrayND[timedelta64], other: _ArrayLikeInt_co) -> _ArrayND[timedelta64]: ... + @overload + def __ifloordiv__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ... + @overload + def __ifloordiv__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ... + + @overload # type: ignore[misc] + def __ipow__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ... + @overload + def __ipow__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ... + @overload + def __ipow__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ... + @overload + def __ipow__(self: _ArrayND[floating[_NBit1]], other: _ArrayLikeFloat_co) -> _ArrayND[floating[_NBit1]]: ... + @overload + def __ipow__(self: _ArrayND[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[_NBit1, _NBit1]]: ... + @overload + def __ipow__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ... + @overload + def __ipow__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ... + + @overload # type: ignore[misc] + def __imod__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ... + @overload + def __imod__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ... + @overload + def __imod__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ... + @overload + def __imod__(self: _ArrayND[floating[_NBit1]], other: _ArrayLikeFloat_co) -> _ArrayND[floating[_NBit1]]: ... + @overload + def __imod__(self: _ArrayND[timedelta64], other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> _ArrayND[timedelta64]: ... + @overload + def __imod__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ... + @overload + def __imod__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ... + + @overload # type: ignore[misc] + def __ilshift__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ... + @overload + def __ilshift__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ... + @overload + def __ilshift__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ... + @overload + def __ilshift__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ... + @overload + def __ilshift__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ... + + @overload # type: ignore[misc] + def __irshift__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ... + @overload + def __irshift__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ... + @overload + def __irshift__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ... + @overload + def __irshift__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ... + @overload + def __irshift__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ... + + @overload # type: ignore[misc] + def __iand__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ... + @overload + def __iand__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ... + @overload + def __iand__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ... + @overload + def __iand__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ... + @overload + def __iand__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ... + @overload + def __iand__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ... + + @overload # type: ignore[misc] + def __ixor__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ... + @overload + def __ixor__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ... + @overload + def __ixor__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ... + @overload + def __ixor__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ... + @overload + def __ixor__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ... + @overload + def __ixor__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ... + + @overload # type: ignore[misc] + def __ior__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ... + @overload + def __ior__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ... + @overload + def __ior__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ... + @overload + def __ior__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ... + @overload + def __ior__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ... + @overload + def __ior__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ... # Keep `dtype` at the bottom to avoid name conflicts with `np.dtype` @property -- cgit v1.2.1