File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 5959if ty .TYPE_CHECKING : # pragma: no cover
6060 import numpy .typing as npt
6161
62+ # Taken from numpy/__init__.pyi
63+ _DType = ty .TypeVar ('_DType' , bound = np .dtype [ty .Any ])
64+
6265
6366class ArrayLike (ty .Protocol ):
6467 """Protocol for numpy ndarray-like objects
@@ -68,9 +71,19 @@ class ArrayLike(ty.Protocol):
6871 """
6972
7073 shape : tuple [int , ...]
71- ndim : int
7274
73- def __array__ (self , dtype : npt .DTypeLike | None = None , / ) -> npt .NDArray :
75+ @property
76+ def ndim (self ) -> int :
77+ ... # pragma: no cover
78+
79+ # If no dtype is passed, any dtype might be returned, depending on the array-like
80+ @ty .overload
81+ def __array__ (self , dtype : None = ..., / ) -> np .ndarray [ty .Any , np .dtype [ty .Any ]]:
82+ ... # pragma: no cover
83+
84+ # Any dtype might be passed, and *that* dtype must be returned
85+ @ty .overload
86+ def __array__ (self , dtype : _DType , / ) -> np .ndarray [ty .Any , _DType ]:
7487 ... # pragma: no cover
7588
7689 def __getitem__ (self , key , / ) -> npt .NDArray :
You can’t perform that action at this time.
0 commit comments