summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/__init__.pyi41
-rw-r--r--numpy/typing/_callable.py124
2 files changed, 160 insertions, 5 deletions
diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi
index 8bcc89bad..27fdbed3d 100644
--- a/numpy/__init__.pyi
+++ b/numpy/__init__.pyi
@@ -28,13 +28,21 @@ from numpy.typing._callable import (
_BoolBitOp,
_BoolSub,
_BoolTrueDiv,
+ _BoolMod,
+ _BoolDivMod,
_TD64Div,
_IntTrueDiv,
_UnsignedIntOp,
_UnsignedIntBitOp,
+ _UnsignedIntMod,
+ _UnsignedIntDivMod,
_SignedIntOp,
_SignedIntBitOp,
+ _SignedIntMod,
+ _SignedIntDivMod,
_FloatOp,
+ _FloatMod,
+ _FloatDivMod,
_ComplexOp,
_NumberOp,
)
@@ -1016,10 +1024,6 @@ class _ArrayOrScalarCommon(
def __ne__(self, other): ...
def __gt__(self, other): ...
def __ge__(self, other): ...
- def __mod__(self, other): ...
- def __rmod__(self, other): ...
- def __divmod__(self, other): ...
- def __rdivmod__(self, other): ...
def astype(
self: _ArraySelf,
dtype: DtypeLike,
@@ -1580,6 +1584,14 @@ class ndarray(_ArrayOrScalarCommon, Iterable, Sized, Container):
def __neg__(self: _ArraySelf) -> Union[_ArraySelf, generic]: ...
def __pos__(self: _ArraySelf) -> Union[_ArraySelf, generic]: ...
def __abs__(self: _ArraySelf) -> Union[_ArraySelf, generic]: ...
+ def __mod__(self, other: ArrayLike) -> Union[ndarray, generic]: ...
+ def __rmod__(self, other: ArrayLike) -> Union[ndarray, generic]: ...
+ def __divmod__(
+ self, other: ArrayLike
+ ) -> Union[Tuple[ndarray, ndarray], Tuple[generic, generic]]: ...
+ def __rdivmod__(
+ self, other: ArrayLike
+ ) -> Union[Tuple[ndarray, ndarray], Tuple[generic, generic]]: ...
def __add__(self, other: ArrayLike) -> Union[ndarray, generic]: ...
def __radd__(self, other: ArrayLike) -> Union[ndarray, generic]: ...
def __sub__(self, other: ArrayLike) -> Union[ndarray, generic]: ...
@@ -1690,6 +1702,10 @@ class bool_(generic):
__rxor__: _BoolBitOp[bool_]
__or__: _BoolBitOp[bool_]
__ror__: _BoolBitOp[bool_]
+ __mod__: _BoolMod
+ __rmod__: _BoolMod
+ __divmod__: _BoolDivMod
+ __rdivmod__: _BoolDivMod
class object_(generic):
def __init__(self, __value: object = ...) -> None: ...
@@ -1735,6 +1751,8 @@ class integer(number[_NBit_co]): # type: ignore
def __index__(self) -> int: ...
__truediv__: _IntTrueDiv[_NBit_co]
__rtruediv__: _IntTrueDiv[_NBit_co]
+ def __mod__(self, value: Union[_IntLike, integer]) -> integer: ...
+ def __rmod__(self, value: Union[_IntLike, integer]) -> integer: ...
def __invert__(self: _IntType) -> _IntType: ...
# Ensure that objects annotated as `integer` support bit-wise operations
def __lshift__(self, other: Union[_IntLike, _BoolLike]) -> integer: ...
@@ -1770,6 +1788,10 @@ class signedinteger(integer[_NBit_co]):
__rxor__: _SignedIntBitOp[_NBit_co]
__or__: _SignedIntBitOp[_NBit_co]
__ror__: _SignedIntBitOp[_NBit_co]
+ __mod__: _SignedIntMod[_NBit_co]
+ __rmod__: _SignedIntMod[_NBit_co]
+ __divmod__: _SignedIntDivMod[_NBit_co]
+ __rdivmod__: _SignedIntDivMod[_NBit_co]
int8 = signedinteger[_8Bit]
int16 = signedinteger[_16Bit]
@@ -1798,6 +1820,9 @@ class timedelta64(generic):
def __rtruediv__(self, other: timedelta64) -> float64: ...
def __rfloordiv__(self, other: timedelta64) -> int64: ...
def __mod__(self, other: timedelta64) -> timedelta64: ...
+ def __rmod__(self, other: timedelta64) -> timedelta64: ...
+ def __divmod__(self, other: timedelta64) -> Tuple[int64, timedelta64]: ...
+ def __rdivmod__(self, other: timedelta64) -> Tuple[int64, timedelta64]: ...
class unsignedinteger(integer[_NBit_co]):
# NOTE: `uint64 + signedinteger -> float64`
@@ -1822,6 +1847,10 @@ class unsignedinteger(integer[_NBit_co]):
__rxor__: _UnsignedIntBitOp[_NBit_co]
__or__: _UnsignedIntBitOp[_NBit_co]
__ror__: _UnsignedIntBitOp[_NBit_co]
+ __mod__: _UnsignedIntMod[_NBit_co]
+ __rmod__: _UnsignedIntMod[_NBit_co]
+ __divmod__: _UnsignedIntDivMod[_NBit_co]
+ __rdivmod__: _UnsignedIntDivMod[_NBit_co]
uint8 = unsignedinteger[_8Bit]
uint16 = unsignedinteger[_16Bit]
@@ -1847,6 +1876,10 @@ class floating(inexact[_NBit_co]):
__rfloordiv__: _FloatOp[_NBit_co]
__pow__: _FloatOp[_NBit_co]
__rpow__: _FloatOp[_NBit_co]
+ __mod__: _FloatMod[_NBit_co]
+ __rmod__: _FloatMod[_NBit_co]
+ __divmod__: _FloatDivMod[_NBit_co]
+ __rdivmod__: _FloatDivMod[_NBit_co]
float16 = floating[_16Bit]
float32 = floating[_32Bit]
diff --git a/numpy/typing/_callable.py b/numpy/typing/_callable.py
index b16891b0e..8b7bfedac 100644
--- a/numpy/typing/_callable.py
+++ b/numpy/typing/_callable.py
@@ -9,7 +9,15 @@ See the `Mypy documentation`_ on protocols for more details.
"""
import sys
-from typing import Union, TypeVar, overload, Any, TYPE_CHECKING, NoReturn
+from typing import (
+ Union,
+ TypeVar,
+ overload,
+ Any,
+ Tuple,
+ NoReturn,
+ TYPE_CHECKING,
+)
from numpy import (
generic,
@@ -19,6 +27,7 @@ from numpy import (
integer,
unsignedinteger,
signedinteger,
+ int8,
int32,
int64,
floating,
@@ -49,9 +58,14 @@ else:
HAVE_PROTOCOL = True
if TYPE_CHECKING or HAVE_PROTOCOL:
+ _T = TypeVar("_T")
+ _2Tuple = Tuple[_T, _T]
+
_NBit_co = TypeVar("_NBit_co", covariant=True, bound=NBitBase)
_NBit = TypeVar("_NBit", bound=NBitBase)
+
_IntType = TypeVar("_IntType", bound=integer)
+ _FloatType = TypeVar("_FloatType", bound=floating)
_NumberType = TypeVar("_NumberType", bound=number)
_NumberType_co = TypeVar("_NumberType_co", covariant=True, bound=number)
_GenericType_co = TypeVar("_GenericType_co", covariant=True, bound=generic)
@@ -97,6 +111,30 @@ if TYPE_CHECKING or HAVE_PROTOCOL:
@overload
def __call__(self, __other: _NumberType) -> _NumberType: ...
+ class _BoolMod(Protocol):
+ @overload
+ def __call__(self, __other: _BoolLike) -> int8: ...
+ @overload # platform dependent
+ def __call__(self, __other: int) -> signedinteger[Any]: ...
+ @overload
+ def __call__(self, __other: float) -> float64: ...
+ @overload
+ def __call__(self, __other: _IntType) -> _IntType: ...
+ @overload
+ def __call__(self, __other: _FloatType) -> _FloatType: ...
+
+ class _BoolDivMod(Protocol):
+ @overload
+ def __call__(self, __other: _BoolLike) -> _2Tuple[int8]: ...
+ @overload # platform dependent
+ def __call__(self, __other: int) -> _2Tuple[signedinteger[Any]]: ...
+ @overload
+ def __call__(self, __other: float) -> _2Tuple[float64]: ...
+ @overload
+ def __call__(self, __other: _IntType) -> _2Tuple[_IntType]: ...
+ @overload
+ def __call__(self, __other: _FloatType) -> _2Tuple[_FloatType]: ...
+
class _TD64Div(Protocol[_NumberType_co]):
@overload
def __call__(self, __other: timedelta64) -> _NumberType_co: ...
@@ -144,6 +182,34 @@ if TYPE_CHECKING or HAVE_PROTOCOL:
self, __other: unsignedinteger[_NBit]
) -> unsignedinteger[Union[_NBit_co, _NBit]]: ...
+ class _UnsignedIntMod(Protocol[_NBit_co]):
+ @overload
+ def __call__(self, __other: bool) -> unsignedinteger[_NBit_co]: ...
+ @overload
+ def __call__(
+ self, __other: Union[int, signedinteger[Any]]
+ ) -> Union[signedinteger[Any], float64]: ...
+ @overload
+ def __call__(self, __other: float) -> float64: ...
+ @overload
+ def __call__(
+ self, __other: unsignedinteger[_NBit]
+ ) -> unsignedinteger[Union[_NBit_co, _NBit]]: ...
+
+ class _UnsignedIntDivMod(Protocol[_NBit_co]):
+ @overload
+ def __call__(self, __other: bool) -> _2Tuple[signedinteger[_NBit_co]]: ...
+ @overload
+ def __call__(
+ self, __other: Union[int, signedinteger[Any]]
+ ) -> Union[_2Tuple[signedinteger[Any]], _2Tuple[float64]]: ...
+ @overload
+ def __call__(self, __other: float) -> _2Tuple[float64]: ...
+ @overload
+ def __call__(
+ self, __other: unsignedinteger[_NBit]
+ ) -> _2Tuple[unsignedinteger[Union[_NBit_co, _NBit]]]: ...
+
class _SignedIntOp(Protocol[_NBit_co]):
@overload
def __call__(self, __other: bool) -> signedinteger[_NBit_co]: ...
@@ -168,6 +234,30 @@ if TYPE_CHECKING or HAVE_PROTOCOL:
self, __other: signedinteger[_NBit]
) -> signedinteger[Union[_NBit_co, _NBit]]: ...
+ class _SignedIntMod(Protocol[_NBit_co]):
+ @overload
+ def __call__(self, __other: bool) -> signedinteger[_NBit_co]: ...
+ @overload
+ def __call__(self, __other: int) -> signedinteger[Any]: ...
+ @overload
+ def __call__(self, __other: float) -> float64: ...
+ @overload
+ def __call__(
+ self, __other: signedinteger[_NBit]
+ ) -> signedinteger[Union[_NBit_co, _NBit]]: ...
+
+ class _SignedIntDivMod(Protocol[_NBit_co]):
+ @overload
+ def __call__(self, __other: bool) -> _2Tuple[signedinteger[_NBit_co]]: ...
+ @overload
+ def __call__(self, __other: int) -> _2Tuple[signedinteger[Any]]: ...
+ @overload
+ def __call__(self, __other: float) -> _2Tuple[float64]: ...
+ @overload
+ def __call__(
+ self, __other: signedinteger[_NBit]
+ ) -> _2Tuple[signedinteger[Union[_NBit_co, _NBit]]]: ...
+
class _FloatOp(Protocol[_NBit_co]):
@overload
def __call__(self, __other: bool) -> floating[_NBit_co]: ...
@@ -182,6 +272,30 @@ if TYPE_CHECKING or HAVE_PROTOCOL:
self, __other: Union[integer[_NBit], floating[_NBit]]
) -> floating[Union[_NBit_co, _NBit]]: ...
+ class _FloatMod(Protocol[_NBit_co]):
+ @overload
+ def __call__(self, __other: bool) -> floating[_NBit_co]: ...
+ @overload
+ def __call__(self, __other: int) -> floating[Any]: ...
+ @overload
+ def __call__(self, __other: float) -> float64: ...
+ @overload
+ def __call__(
+ self, __other: Union[integer[_NBit], floating[_NBit]]
+ ) -> floating[Union[_NBit_co, _NBit]]: ...
+
+ class _FloatDivMod(Protocol[_NBit_co]):
+ @overload
+ def __call__(self, __other: bool) -> _2Tuple[floating[_NBit_co]]: ...
+ @overload
+ def __call__(self, __other: int) -> _2Tuple[floating[Any]]: ...
+ @overload
+ def __call__(self, __other: float) -> _2Tuple[float64]: ...
+ @overload
+ def __call__(
+ self, __other: Union[integer[_NBit], floating[_NBit]]
+ ) -> _2Tuple[floating[Union[_NBit_co, _NBit]]]: ...
+
class _ComplexOp(Protocol[_NBit_co]):
@overload
def __call__(self, __other: bool) -> complexfloating[_NBit_co, _NBit_co]: ...
@@ -207,12 +321,20 @@ else:
_BoolBitOp = Any
_BoolSub = Any
_BoolTrueDiv = Any
+ _BoolMod = Any
+ _BoolDivMod = Any
_TD64Div = Any
_IntTrueDiv = Any
_UnsignedIntOp = Any
_UnsignedIntBitOp = Any
+ _UnsignedIntMod = Any
+ _UnsignedIntDivMod = Any
_SignedIntOp = Any
_SignedIntBitOp = Any
+ _SignedIntMod = Any
+ _SignedIntDivMod = Any
_FloatOp = Any
+ _FloatMod = Any
+ _FloatDivMod = Any
_ComplexOp = Any
_NumberOp = Any