summaryrefslogtreecommitdiff
path: root/numpy/tests/pass/array_like.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/tests/pass/array_like.py')
-rw-r--r--numpy/tests/pass/array_like.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/numpy/tests/pass/array_like.py b/numpy/tests/pass/array_like.py
new file mode 100644
index 000000000..098149c4b
--- /dev/null
+++ b/numpy/tests/pass/array_like.py
@@ -0,0 +1,44 @@
+from typing import Any, List, Optional, TYPE_CHECKING
+
+import numpy as np
+
+if TYPE_CHECKING:
+ from numpy.typing import ArrayLike, DtypeLike, _SupportsArray
+else:
+ ArrayLike = Any
+ DtypeLike = Any
+ _SupportsArray = Any
+
+x1: ArrayLike = True
+x2: ArrayLike = 5
+x3: ArrayLike = 1.0
+x4: ArrayLike = 1 + 1j
+x5: ArrayLike = np.int8(1)
+x6: ArrayLike = np.float64(1)
+x7: ArrayLike = np.complex128(1)
+x8: ArrayLike = np.array([1, 2, 3])
+x9: ArrayLike = [1, 2, 3]
+x10: ArrayLike = (1, 2, 3)
+x11: ArrayLike = "foo"
+
+
+class A:
+ def __array__(self, dtype: DtypeLike = None) -> np.ndarray:
+ return np.array([1, 2, 3])
+
+
+x12: ArrayLike = A()
+
+scalar: _SupportsArray = np.int64(1)
+scalar.__array__(np.float64)
+array: _SupportsArray = np.array(1)
+array.__array__(np.float64)
+
+a: _SupportsArray = A()
+a.__array__(np.int64)
+a.__array__(dtype=np.int64)
+
+# Escape hatch for when you mean to make something like an object
+# array.
+object_array_scalar: Any = (i for i in range(10))
+np.array(object_array_scalar)