summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorBas van Beek <43369155+BvB93@users.noreply.github.com>2020-09-01 14:10:36 +0200
committerGitHub <noreply@github.com>2020-09-01 13:10:36 +0100
commit3fbc84a5662ffd985a071b0bbdcd59e655041ad3 (patch)
tree8e162e1fa2ff6b476139fba8d2d0c36f60af6f38 /numpy
parent263b293d9caf8f54183509275a853de9b8d8839f (diff)
downloadnumpy-3fbc84a5662ffd985a071b0bbdcd59e655041ad3.tar.gz
ENH: typing: Make `np.complexfloating` generic w.r.t. `np.floating` (#17172)
Diffstat (limited to 'numpy')
-rw-r--r--numpy/__init__.pyi21
-rw-r--r--numpy/tests/typing/reveal/scalars.py3
2 files changed, 13 insertions, 11 deletions
diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi
index 8d65c23c4..d7f272616 100644
--- a/numpy/__init__.pyi
+++ b/numpy/__init__.pyi
@@ -462,6 +462,8 @@ class uint64(unsignedinteger):
class inexact(number): ... # type: ignore
class floating(inexact, _real_generic): ... # type: ignore
+_FloatType = TypeVar('_FloatType', bound=floating)
+
class float16(floating):
def __init__(self, __value: Optional[SupportsFloat] = ...) -> None: ...
@@ -471,27 +473,24 @@ class float32(floating):
class float64(floating):
def __init__(self, __value: Optional[SupportsFloat] = ...) -> None: ...
-class complexfloating(inexact): ... # type: ignore
+class complexfloating(inexact, Generic[_FloatType]): # type: ignore
+ @property
+ def real(self) -> _FloatType: ...
+ @property
+ def imag(self) -> _FloatType: ...
+ def __abs__(self) -> _FloatType: ... # type: ignore[override]
-class complex64(complexfloating):
+class complex64(complexfloating[float32]):
def __init__(
self,
__value: Union[None, SupportsInt, SupportsFloat, SupportsComplex] = ...
) -> None: ...
- @property
- def real(self) -> float32: ...
- @property
- def imag(self) -> float32: ...
-class complex128(complexfloating):
+class complex128(complexfloating[float64]):
def __init__(
self,
__value: Union[None, SupportsInt, SupportsFloat, SupportsComplex] = ...
) -> None: ...
- @property
- def real(self) -> float64: ...
- @property
- def imag(self) -> float64: ...
class flexible(_real_generic): ... # type: ignore
diff --git a/numpy/tests/typing/reveal/scalars.py b/numpy/tests/typing/reveal/scalars.py
index 8a9555fc3..882fe9612 100644
--- a/numpy/tests/typing/reveal/scalars.py
+++ b/numpy/tests/typing/reveal/scalars.py
@@ -28,3 +28,6 @@ reveal_type(td - 1) # E: numpy.timedelta64
reveal_type(td / 1.0) # E: numpy.timedelta64
reveal_type(td / td) # E: float
reveal_type(td % td) # E: numpy.timedelta64
+
+reveal_type(np.complex64().real) # E: numpy.float32
+reveal_type(np.complex128().imag) # E: numpy.float64