diff options
| author | Charles Harris <charlesr.harris@gmail.com> | 2020-09-07 10:51:40 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-07 10:51:40 -0600 |
| commit | 9c9df9c649361fb651f4b2174e779b3036464ab4 (patch) | |
| tree | 969aad71a367d76f1f3d2be79e34ebccde154731 /numpy/tests | |
| parent | dec8879b4b6b032e168a417b342056d000d4318e (diff) | |
| parent | b53bd5a06284bcd417e1b557e5515cbef9083b2c (diff) | |
| download | numpy-9c9df9c649361fb651f4b2174e779b3036464ab4.tar.gz | |
Merge pull request #17214 from BvB93/generic
MAINT: Fix various issues with the `np.generic` annotations
Diffstat (limited to 'numpy/tests')
| -rw-r--r-- | numpy/tests/test_typing.py | 2 | ||||
| -rw-r--r-- | numpy/tests/typing/fail/scalars.py | 11 | ||||
| -rw-r--r-- | numpy/tests/typing/pass/scalars.py | 37 |
3 files changed, 43 insertions, 7 deletions
diff --git a/numpy/tests/test_typing.py b/numpy/tests/test_typing.py index 04ea3c64d..32342d321 100644 --- a/numpy/tests/test_typing.py +++ b/numpy/tests/test_typing.py @@ -89,7 +89,7 @@ def test_fail(path): for i, line in enumerate(lines): lineno = i + 1 - if " E:" not in line and lineno not in errors: + if line.startswith('#') or (" E:" not in line and lineno not in errors): continue target_line = lines[lineno - 1] diff --git a/numpy/tests/typing/fail/scalars.py b/numpy/tests/typing/fail/scalars.py index 5d7221895..47c031163 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 # E: No overload +# td_64 % dt_64 # E: Unsupported operand types class A: diff --git a/numpy/tests/typing/pass/scalars.py b/numpy/tests/typing/pass/scalars.py index 1c7ace282..c02e1ed36 100644 --- a/numpy/tests/typing/pass/scalars.py +++ b/numpy/tests/typing/pass/scalars.py @@ -1,27 +1,38 @@ +import sys +import datetime as dt + import numpy as np # Construction +class D: + def __index__(self) -> int: + return 0 + + class C: - def __complex__(self): + def __complex__(self) -> complex: return 3j class B: - def __int__(self): + def __int__(self) -> int: return 4 class A: - def __float__(self): + def __float__(self) -> float: return 4.0 np.complex64(3j) +np.complex64(A()) np.complex64(C()) np.complex128(3j) np.complex128(C()) np.complex128(None) +np.complex64("1.2") +np.complex128(b"2j") np.int8(4) np.int16(3.4) @@ -29,11 +40,20 @@ np.int32(4) np.int64(-1) np.uint8(B()) np.uint32() +np.int32("1") +np.int64(b"2") np.float16(A()) np.float32(16) np.float64(3.0) np.float64(None) +np.float32("1") +np.float16(b"2.5") + +if sys.version_info >= (3, 8): + np.uint64(D()) + np.float32(D()) + np.complex64(D()) np.bytes_(b"hello") np.bytes_("hello", 'utf-8') @@ -66,14 +86,25 @@ np.uint64().shape # Time structures np.datetime64() np.datetime64(0, "D") +np.datetime64(0, b"D") +np.datetime64(0, ('ms', 3)) np.datetime64("2019") +np.datetime64(b"2019") np.datetime64("2019", "D") +np.datetime64(np.datetime64()) +np.datetime64(dt.datetime(2000, 5, 3)) np.datetime64(None) np.datetime64(None, "D") np.timedelta64() np.timedelta64(0) np.timedelta64(0, "D") +np.timedelta64(0, ('ms', 3)) +np.timedelta64(0, b"D") +np.timedelta64("3") +np.timedelta64(b"5") +np.timedelta64(np.timedelta64(2)) +np.timedelta64(dt.timedelta(2)) np.timedelta64(None) np.timedelta64(None, "D") |
