summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorBas van Beek <b.f.van.beek@vu.nl>2020-09-01 15:56:48 +0200
committerBas van Beek <b.f.van.beek@vu.nl>2020-09-01 15:56:48 +0200
commit8f2c26d8cb5df534db9eaccfea26691369c3e5aa (patch)
treed967fbaf5c12be2dcd9f42c3bd0b868438554a9e /numpy
parentd6b0c70514c6d306f438208f9d5ba988b0f747d5 (diff)
downloadnumpy-8f2c26d8cb5df534db9eaccfea26691369c3e5aa.tar.gz
MAINT: Make `datetime64` a `generic` subclass (again)
Diffstat (limited to 'numpy')
-rw-r--r--numpy/__init__.pyi11
-rw-r--r--numpy/tests/typing/fail/scalars.py11
2 files changed, 13 insertions, 9 deletions
diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi
index c0f594dbf..8da12e1b8 100644
--- a/numpy/__init__.pyi
+++ b/numpy/__init__.pyi
@@ -408,7 +408,7 @@ class object_(generic):
@property
def imag(self: _ArraySelf) -> _ArraySelf: ...
-class datetime64:
+class datetime64(generic):
@overload
def __init__(
self,
@@ -419,6 +419,7 @@ class datetime64:
def __init__(self, __value: int, __format: Union[str, bytes]) -> None: ...
def __add__(self, other: Union[timedelta64, int]) -> datetime64: ...
def __sub__(self, other: Union[timedelta64, datetime64, int]) -> timedelta64: ...
+ def __rsub__(self, other: Union[datetime64, int]) -> timedelta64: ...
class integer(number): ... # type: ignore
class signedinteger(integer): ... # type: ignore
@@ -454,16 +455,14 @@ class timedelta64(signedinteger):
@overload
def __add__(self, other: datetime64) -> datetime64: ...
def __sub__(self, other: Union[timedelta64, int]) -> timedelta64: ...
- if sys.version_info[0] < 3:
- @overload
- def __div__(self, other: timedelta64) -> float: ...
- @overload
- def __div__(self, other: float) -> timedelta64: ...
+ def __rsub__(self, other: Union[timedelta64, int]) -> timedelta64: ...
@overload
def __truediv__(self, other: timedelta64) -> float: ...
@overload
def __truediv__(self, other: float) -> timedelta64: ...
+ def __rtruediv__(self, other: timedelta64) -> float: ...
def __mod__(self, other: timedelta64) -> timedelta64: ...
+ def __rmod__(self, other: timedelta64) -> timedelta64: ...
class unsignedinteger(integer): ... # type: ignore
diff --git a/numpy/tests/typing/fail/scalars.py b/numpy/tests/typing/fail/scalars.py
index 5d7221895..cd6db804f 100644
--- a/numpy/tests/typing/fail/scalars.py
+++ b/numpy/tests/typing/fail/scalars.py
@@ -32,11 +32,16 @@ dt_64 = np.datetime64(0, "D")
td_64 = np.timedelta64(1, "h")
dt_64 + dt_64 # E: Unsupported operand types
-
td_64 - dt_64 # E: Unsupported operand types
-td_64 / dt_64 # E: No overload
td_64 % 1 # E: Unsupported operand types
-td_64 % dt_64 # E: Unsupported operand types
+
+# NOTE: The 2 tests below currently don't work due to the broad
+# (i.e. untyped) signature of `generic.__truediv__()` and `.__mod__()`.
+# TODO: Revisit this once annotations are added to the
+# `_ArrayOrScalarCommon` magic methods.
+
+# td_64 / dt_64 No overload
+# td_64 % dt_64 Unsupported operand types
class A: