Skip to content
This repository was archived by the owner on Jun 10, 2020. It is now read-only.

Commit 6579ac3

Browse files
committed
MAINT: add more tests for __array__
1 parent e30b16a commit 6579ac3

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

tests/fail/array_like.py

+5
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ class A:
88
x1: "np.ArrayLike" = (i for i in range(10)) # E: Incompatible types in assignment
99
x2: "np.ArrayLike" = A() # E: Incompatible types in assignment
1010
x3: "np.ArrayLike" = {1: "foo", 2: "bar"} # E: Incompatible types in assignment
11+
12+
scalar = np.int64(1)
13+
scalar.__array__(dtype=np.float64) # E: Unexpected keyword argument
14+
array = np.array([1])
15+
array.__array__(dtype=np.float64) # E: Unexpected keyword argument

tests/pass/array_like.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,21 @@
1515
x11: "np.ArrayLike" = "foo"
1616

1717

18-
class B:
18+
class A:
1919
def __array__(self, dtype: Optional["np.DtypeLike"] = None) -> np.ndarray:
2020
return np.array([1, 2, 3])
2121

2222

23-
x12: "np.ArrayLike" = B()
24-
x13: "np._SupportsArray" = np.int64(1)
25-
x14: "np._SupportsArray" = np.array(1)
23+
x12: "np.ArrayLike" = A()
24+
25+
scalar: "np._SupportsArray" = np.int64(1)
26+
scalar.__array__(np.float64)
27+
array: "np._SupportsArray" = np.array(1)
28+
array.__array__(np.float64)
29+
30+
a: "np._SupportsArray" = A()
31+
a.__array__(np.int64)
32+
a.__array__(dtype=np.int64)
2633

2734
# Escape hatch for when you mean to make something like an object
2835
# array.

0 commit comments

Comments
 (0)