summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorBas van Beek <b.f.van.beek@vu.nl>2021-05-13 14:55:16 +0200
committerBas van Beek <b.f.van.beek@vu.nl>2021-05-13 20:00:44 +0200
commita1a9ffe96fd4b83135c9898c1e096e3fe2193fb6 (patch)
treeee2f05041685f5139d449532807143fce447995d /numpy
parent8aaee9fe3015a07c20cc0db8d45ba424b892fc96 (diff)
downloadnumpy-a1a9ffe96fd4b83135c9898c1e096e3fe2193fb6.tar.gz
ENH: Add dtype-support to 4 `ndarray` magic methods
* `__int__` * `__float__` * `__complex__` * `__index__`
Diffstat (limited to 'numpy')
-rw-r--r--numpy/__init__.pyi22
1 files changed, 18 insertions, 4 deletions
diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi
index 5c552e901..610343dc7 100644
--- a/numpy/__init__.pyi
+++ b/numpy/__init__.pyi
@@ -1877,13 +1877,22 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
self, *shape: SupportsIndex, order: _OrderACF = ...
) -> ndarray[Any, _DType_co]: ...
- def __int__(self) -> int: ...
+ # Dispatch to the underlying `generic` via protocols
+ def __int__(
+ self: ndarray[Any, dtype[SupportsInt]], # type: ignore[type-var]
+ ) -> int: ...
- def __float__(self) -> float: ...
+ def __float__(
+ self: ndarray[Any, dtype[SupportsFloat]], # type: ignore[type-var]
+ ) -> float: ...
- def __complex__(self) -> complex: ...
+ def __complex__(
+ self: ndarray[Any, dtype[SupportsComplex]], # type: ignore[type-var]
+ ) -> complex: ...
- def __index__(self) -> int: ...
+ def __index__(
+ self: ndarray[Any, dtype[SupportsIndex]], # type: ignore[type-var]
+ ) -> int: ...
def __len__(self) -> int: ...
def __setitem__(self, key, value): ...
@@ -2987,6 +2996,11 @@ class object_(generic):
def real(self: _ArraySelf) -> _ArraySelf: ...
@property
def imag(self: _ArraySelf) -> _ArraySelf: ...
+ # The 3 protocols below may or may not raise,
+ # depending on the underlying object
+ def __int__(self) -> int: ...
+ def __float__(self) -> float: ...
+ def __complex__(self) -> complex: ...
object0 = object_