diff options
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/__init__.pyi | 25 | ||||
| -rw-r--r-- | numpy/typing/_callable.py | 9 |
2 files changed, 30 insertions, 4 deletions
diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi index 2366e9b75..ad37979ed 100644 --- a/numpy/__init__.pyi +++ b/numpy/__init__.pyi @@ -47,6 +47,7 @@ from numpy.typing._callable import ( _FloatDivMod, _ComplexOp, _NumberOp, + _ComparisonOp, ) from typing import ( @@ -1013,12 +1014,8 @@ class _ArrayOrScalarCommon: def __repr__(self) -> str: ... def __copy__(self: _ArraySelf) -> _ArraySelf: ... def __deepcopy__(self: _ArraySelf, __memo: Optional[dict] = ...) -> _ArraySelf: ... - def __lt__(self, other): ... - def __le__(self, other): ... def __eq__(self, other): ... def __ne__(self, other): ... - def __gt__(self, other): ... - def __ge__(self, other): ... def astype( self: _ArraySelf, dtype: DTypeLike, @@ -1579,6 +1576,10 @@ class ndarray(_ArrayOrScalarCommon, Iterable, Sized, Container): def __iter__(self) -> Any: ... def __contains__(self, key) -> bool: ... def __index__(self) -> int: ... + def __lt__(self, other: ArrayLike) -> Union[ndarray, bool_]: ... + def __le__(self, other: ArrayLike) -> Union[ndarray, bool_]: ... + def __gt__(self, other: ArrayLike) -> Union[ndarray, bool_]: ... + def __ge__(self, other: ArrayLike) -> Union[ndarray, bool_]: ... def __matmul__(self, other: ArrayLike) -> Any: ... # NOTE: `ndarray` does not implement `__imatmul__` def __rmatmul__(self, other: ArrayLike) -> Any: ... @@ -1689,6 +1690,10 @@ class number(generic, Generic[_NBit_co]): # type: ignore __rpow__: _NumberOp __truediv__: _NumberOp __rtruediv__: _NumberOp + __lt__: _ComparisonOp[_NumberLike] + __le__: _ComparisonOp[_NumberLike] + __gt__: _ComparisonOp[_NumberLike] + __ge__: _ComparisonOp[_NumberLike] class bool_(generic): def __init__(self, __value: object = ...) -> None: ... @@ -1727,6 +1732,10 @@ class bool_(generic): __rmod__: _BoolMod __divmod__: _BoolDivMod __rdivmod__: _BoolDivMod + __lt__: _ComparisonOp[_NumberLike] + __le__: _ComparisonOp[_NumberLike] + __gt__: _ComparisonOp[_NumberLike] + __ge__: _ComparisonOp[_NumberLike] class object_(generic): def __init__(self, __value: object = ...) -> None: ... @@ -1755,6 +1764,10 @@ class datetime64(generic): @overload def __sub__(self, other: Union[timedelta64, _IntLike, _BoolLike]) -> datetime64: ... def __rsub__(self, other: datetime64) -> timedelta64: ... + __lt__: _ComparisonOp[datetime64] + __le__: _ComparisonOp[datetime64] + __gt__: _ComparisonOp[datetime64] + __ge__: _ComparisonOp[datetime64] # Support for `__index__` was added in python 3.8 (bpo-20092) if sys.version_info >= (3, 8): @@ -1845,6 +1858,10 @@ class timedelta64(generic): def __rmod__(self, other: timedelta64) -> timedelta64: ... def __divmod__(self, other: timedelta64) -> Tuple[int64, timedelta64]: ... def __rdivmod__(self, other: timedelta64) -> Tuple[int64, timedelta64]: ... + __lt__: _ComparisonOp[Union[timedelta64, _IntLike, _BoolLike]] + __le__: _ComparisonOp[Union[timedelta64, _IntLike, _BoolLike]] + __gt__: _ComparisonOp[Union[timedelta64, _IntLike, _BoolLike]] + __ge__: _ComparisonOp[Union[timedelta64, _IntLike, _BoolLike]] class unsignedinteger(integer[_NBit_co]): # NOTE: `uint64 + signedinteger -> float64` diff --git a/numpy/typing/_callable.py b/numpy/typing/_callable.py index 91b7a4ec2..c703df28a 100644 --- a/numpy/typing/_callable.py +++ b/numpy/typing/_callable.py @@ -20,6 +20,7 @@ from typing import ( ) from numpy import ( + ndarray, generic, bool_, timedelta64, @@ -41,6 +42,7 @@ from ._scalars import ( _NumberLike, ) from . import NBitBase +from ._array_like import ArrayLike if sys.version_info >= (3, 8): from typing import Protocol @@ -312,6 +314,12 @@ if TYPE_CHECKING or HAVE_PROTOCOL: class _NumberOp(Protocol): def __call__(self, __other: _NumberLike) -> number: ... + class _ComparisonOp(Protocol[_T]): + @overload + def __call__(self, __other: _T) -> bool_: ... + @overload + def __call__(self, __other: ArrayLike) -> Union[ndarray, bool_]: ... + else: _BoolOp = Any _BoolBitOp = Any @@ -334,3 +342,4 @@ else: _FloatDivMod = Any _ComplexOp = Any _NumberOp = Any + _ComparisonOp = Any |
