diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/typing/tests/data/fail/scalars.py | 2 | ||||
-rw-r--r-- | numpy/typing/tests/data/pass/scalars.py | 53 |
2 files changed, 45 insertions, 10 deletions
diff --git a/numpy/typing/tests/data/fail/scalars.py b/numpy/typing/tests/data/fail/scalars.py index e7c4c7485..5fffa89b1 100644 --- a/numpy/typing/tests/data/fail/scalars.py +++ b/numpy/typing/tests/data/fail/scalars.py @@ -64,3 +64,5 @@ np.timedelta64(value=0) # E: Unexpected keyword argument np.bytes_(b"hello", encoding='utf-8') # E: No overload variant np.str_("hello", encoding='utf-8') # E: No overload variant + +complex(np.bytes_("1")) # E: No overload variant diff --git a/numpy/typing/tests/data/pass/scalars.py b/numpy/typing/tests/data/pass/scalars.py index 49ddb8ed9..04e974983 100644 --- a/numpy/typing/tests/data/pass/scalars.py +++ b/numpy/typing/tests/data/pass/scalars.py @@ -1,6 +1,7 @@ import sys import datetime as dt +import pytest import numpy as np @@ -62,16 +63,6 @@ np.str_("hello") np.str_(b"hello", 'utf-8') np.str_(b"hello", encoding='utf-8') -# Protocols -float(np.int8(4)) -int(np.int16(5)) -np.int8(np.float32(6)) - -# TODO(alan): test after https://github.com/python/typeshed/pull/2004 -# complex(np.int32(8)) - -abs(np.int8(4)) - # Array-ish semantics np.int8().real np.int16().imag @@ -114,3 +105,45 @@ np.void(True) np.void(np.bool_(True)) np.void(b"test") np.void(np.bytes_("test")) + +# Protocols +i8 = np.int64() +u8 = np.uint64() +f8 = np.float64() +c16 = np.complex128() +b_ = np.bool_() +td = np.timedelta64() +U = np.str_("1") +S = np.bytes_("1") +AR = np.array(1, dtype=np.float64) + +int(i8) +int(u8) +int(f8) +int(b_) +int(td) +int(U) +int(S) +int(AR) +with pytest.warns(np.ComplexWarning): + int(c16) + +float(i8) +float(u8) +float(f8) +float(b_) +float(td) +float(U) +float(S) +float(AR) +with pytest.warns(np.ComplexWarning): + float(c16) + +complex(i8) +complex(u8) +complex(f8) +complex(c16) +complex(b_) +complex(td) +complex(U) +complex(AR) |