summaryrefslogtreecommitdiff
path: root/numpy/tests/typing/pass/scalars.py
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2020-06-09 08:25:36 +0300
committerGitHub <noreply@github.com>2020-06-09 08:25:36 +0300
commite73c8e5479297f235b37fba91d6d0e8464be66a6 (patch)
tree713099e98dbc7f9c3d0d87564faac52e2046b463 /numpy/tests/typing/pass/scalars.py
parentd647ef2d98852e322d487d6045d5860223dcda79 (diff)
parent2e238e411a4875d470a40cd0c351056ca30882ed (diff)
downloadnumpy-e73c8e5479297f235b37fba91d6d0e8464be66a6.tar.gz
Merge pull request #16515 from person142/add-type-stubs
ENH: add type stubs from numpy-stubs
Diffstat (limited to 'numpy/tests/typing/pass/scalars.py')
-rw-r--r--numpy/tests/typing/pass/scalars.py88
1 files changed, 88 insertions, 0 deletions
diff --git a/numpy/tests/typing/pass/scalars.py b/numpy/tests/typing/pass/scalars.py
new file mode 100644
index 000000000..bd055673b
--- /dev/null
+++ b/numpy/tests/typing/pass/scalars.py
@@ -0,0 +1,88 @@
+import numpy as np
+
+
+# Construction
+class C:
+ def __complex__(self):
+ return 3j
+
+
+class B:
+ def __int__(self):
+ return 4
+
+
+class A:
+ def __float__(self):
+ return 4.0
+
+
+np.complex64(3j)
+np.complex64(C())
+np.complex128(3j)
+np.complex128(C())
+
+np.int8(4)
+np.int16(3.4)
+np.int32(4)
+np.int64(-1)
+np.uint8(B())
+np.uint32()
+
+np.float16(A())
+np.float32(16)
+np.float64(3.0)
+
+np.bytes_(b"hello")
+np.str_("hello")
+
+# 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
+np.int32().data
+np.int64().flags
+
+np.uint8().itemsize * 2
+np.uint16().ndim + 1
+np.uint32().strides
+np.uint64().shape
+
+# Time structures
+np.datetime64()
+np.datetime64(0, "D")
+np.datetime64("2019")
+np.datetime64("2019", "D")
+
+np.timedelta64()
+np.timedelta64(0)
+np.timedelta64(0, "D")
+
+dt_64 = np.datetime64(0, "D")
+td_64 = np.timedelta64(1, "h")
+
+dt_64 + td_64
+dt_64 - dt_64
+dt_64 - td_64
+
+td_64 + td_64
+td_64 - td_64
+td_64 / 1.0
+td_64 / td_64
+td_64 % td_64
+
+np.void(1)
+np.void(np.int64(1))
+np.void(True)
+np.void(np.bool_(True))
+np.void(b"test")
+np.void(np.bytes_("test"))