summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Wilson <person142@users.noreply.github.com>2020-07-05 16:42:05 -0700
committerGitHub <noreply@github.com>2020-07-05 16:42:05 -0700
commit2ccfd794011ece560ba4bbeca6f9171176428a77 (patch)
tree2057b108b374b13835760647b7fc26d80b6be24e
parente641d8b35484d786f399e8cd9349b2a6c09269d1 (diff)
parente5e75ccfb8d07151d8608b35bd6ac5006df6467e (diff)
downloadnumpy-2ccfd794011ece560ba4bbeca6f9171176428a77.tar.gz
Merge pull request #16684 from BvB93/generic
MAINT: Allow `None` to be passed to certain `generic` subclasses
-rw-r--r--numpy/__init__.pyi16
-rw-r--r--numpy/tests/typing/pass/scalars.py6
2 files changed, 16 insertions, 6 deletions
diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi
index 847b451f7..ff2cc565e 100644
--- a/numpy/__init__.pyi
+++ b/numpy/__init__.pyi
@@ -395,7 +395,9 @@ class object_(generic):
class datetime64:
@overload
def __init__(
- self, __value: Union[datetime64, str, dt.datetime] = ..., __format: str = ...
+ self,
+ __value: Union[None, datetime64, str, dt.datetime] = ...,
+ __format: str = ...
) -> None: ...
@overload
def __init__(self, __value: int, __format: str) -> None: ...
@@ -453,19 +455,20 @@ class inexact(number): ... # type: ignore
class floating(inexact, _real_generic): ... # type: ignore
class float16(floating):
- def __init__(self, __value: SupportsFloat = ...) -> None: ...
+ def __init__(self, __value: Optional[SupportsFloat] = ...) -> None: ...
class float32(floating):
- def __init__(self, __value: SupportsFloat = ...) -> None: ...
+ def __init__(self, __value: Optional[SupportsFloat] = ...) -> None: ...
class float64(floating):
- def __init__(self, __value: SupportsFloat = ...) -> None: ...
+ def __init__(self, __value: Optional[SupportsFloat] = ...) -> None: ...
class complexfloating(inexact): ... # type: ignore
class complex64(complexfloating):
def __init__(
- self, __value: Union[SupportsInt, SupportsFloat, SupportsComplex] = ...
+ self,
+ __value: Union[None, SupportsInt, SupportsFloat, SupportsComplex] = ...
) -> None: ...
@property
def real(self) -> float32: ...
@@ -474,7 +477,8 @@ class complex64(complexfloating):
class complex128(complexfloating):
def __init__(
- self, __value: Union[SupportsInt, SupportsFloat, SupportsComplex] = ...
+ self,
+ __value: Union[None, SupportsInt, SupportsFloat, SupportsComplex] = ...
) -> None: ...
@property
def real(self) -> float64: ...
diff --git a/numpy/tests/typing/pass/scalars.py b/numpy/tests/typing/pass/scalars.py
index 7de182626..1c7ace282 100644
--- a/numpy/tests/typing/pass/scalars.py
+++ b/numpy/tests/typing/pass/scalars.py
@@ -21,6 +21,7 @@ np.complex64(3j)
np.complex64(C())
np.complex128(3j)
np.complex128(C())
+np.complex128(None)
np.int8(4)
np.int16(3.4)
@@ -32,6 +33,7 @@ np.uint32()
np.float16(A())
np.float32(16)
np.float64(3.0)
+np.float64(None)
np.bytes_(b"hello")
np.bytes_("hello", 'utf-8')
@@ -66,10 +68,14 @@ np.datetime64()
np.datetime64(0, "D")
np.datetime64("2019")
np.datetime64("2019", "D")
+np.datetime64(None)
+np.datetime64(None, "D")
np.timedelta64()
np.timedelta64(0)
np.timedelta64(0, "D")
+np.timedelta64(None)
+np.timedelta64(None, "D")
dt_64 = np.datetime64(0, "D")
td_64 = np.timedelta64(1, "h")