@@ -210,7 +210,7 @@ from typing import (
210
210
# library include `typing_extensions` stubs:
211
211
# https://github.com/python/typeshed/blob/main/stdlib/typing_extensions.pyi
212
212
from _typeshed import StrOrBytesPath , SupportsFlush , SupportsLenAndGetItem , SupportsWrite
213
- from typing_extensions import CapsuleType , Generic , LiteralString , Protocol , Self , TypeVar , deprecated , overload
213
+ from typing_extensions import CapsuleType , Generic , LiteralString , Protocol , Self , TypeVar , Unpack , deprecated , overload
214
214
215
215
from numpy import (
216
216
core ,
@@ -1792,6 +1792,8 @@ _ArrayComplex_co: TypeAlias = NDArray[np.bool | integer[Any] | floating[Any] | c
1792
1792
_ArrayNumber_co : TypeAlias = NDArray [np .bool | number [Any ]]
1793
1793
_ArrayTD64_co : TypeAlias = NDArray [np .bool | integer [Any ] | timedelta64 ]
1794
1794
1795
+ _ArrayIndexLike : TypeAlias = SupportsIndex | slice | EllipsisType | _ArrayLikeInt_co | None
1796
+
1795
1797
# Introduce an alias for `dtype` to avoid naming conflicts.
1796
1798
_dtype : TypeAlias = dtype [_ScalarType ]
1797
1799
@@ -1906,26 +1908,20 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType_co, _DType_co]):
1906
1908
) -> ndarray [_ShapeType , _DType ]: ...
1907
1909
1908
1910
@overload
1909
- def __getitem__ (self , key : (
1910
- NDArray [integer [Any ]]
1911
- | NDArray [np .bool ]
1912
- | tuple [NDArray [integer [Any ]] | NDArray [np .bool ], ...]
1913
- )) -> ndarray [_Shape , _DType_co ]: ...
1911
+ def __getitem__ (self , key : _ArrayInt_co | tuple [_ArrayInt_co , ...], / ) -> ndarray [_Shape , _DType_co ]: ...
1912
+ @overload
1913
+ def __getitem__ (self , key : SupportsIndex | tuple [SupportsIndex , ...], / ) -> Any : ...
1914
1914
@overload
1915
- def __getitem__ (self , key : SupportsIndex | tuple [SupportsIndex , ...]) -> Any : ...
1915
+ def __getitem__ (self , key : _ArrayIndexLike | tuple [_ArrayIndexLike , ...], / ) -> ndarray [ _Shape , _DType_co ] : ...
1916
1916
@overload
1917
- def __getitem__ (self , key : (
1918
- None
1919
- | slice
1920
- | EllipsisType
1921
- | SupportsIndex
1922
- | _ArrayLikeInt_co
1923
- | tuple [None | slice | EllipsisType | _ArrayLikeInt_co | SupportsIndex , ...]
1924
- )) -> ndarray [_Shape , _DType_co ]: ...
1917
+ def __getitem__ (self : NDArray [void ], key : str , / ) -> ndarray [_ShapeType_co , np .dtype [Any ]]: ...
1918
+ @overload
1919
+ def __getitem__ (self : NDArray [void ], key : list [str ], / ) -> ndarray [_ShapeType_co , _dtype [void ]]: ...
1920
+
1925
1921
@overload
1926
- def __getitem__ (self : NDArray [void ], key : str ) -> NDArray [ Any ] : ...
1922
+ def __setitem__ (self : NDArray [void ], key : str | list [ str ], value : ArrayLike , / ) -> None : ...
1927
1923
@overload
1928
- def __getitem__ (self : NDArray [ void ], key : list [ str ] ) -> ndarray [ _ShapeType_co , _dtype [ void ]] : ...
1924
+ def __setitem__ (self , key : _ArrayIndexLike | tuple [ _ArrayIndexLike , ... ], value : ArrayLike , / ) -> None : ...
1929
1925
1930
1926
@property
1931
1927
def ctypes (self ) -> _ctypes [int ]: ...
@@ -2272,9 +2268,16 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType_co, _DType_co]):
2272
2268
def __complex__ (self : NDArray [number [Any ] | np .bool | object_ ], / ) -> complex : ...
2273
2269
2274
2270
def __len__ (self ) -> int : ...
2275
- def __setitem__ (self , key , value ): ...
2276
- def __iter__ (self ) -> Any : ...
2277
- def __contains__ (self , key ) -> builtins .bool : ...
2271
+ def __contains__ (self , value : object , / ) -> builtins .bool : ...
2272
+
2273
+ @overload # == 1-d & object_
2274
+ def __iter__ (self : ndarray [tuple [int ], dtype [object_ ]], / ) -> Iterator [Any ]: ...
2275
+ @overload # == 1-d
2276
+ def __iter__ (self : ndarray [tuple [int ], dtype [_SCT ]], / ) -> Iterator [_SCT ]: ...
2277
+ @overload # >= 2-d
2278
+ def __iter__ (self : ndarray [tuple [int , int , Unpack [tuple [int , ...]]], dtype [_SCT ]], / ) -> Iterator [NDArray [_SCT ]]: ...
2279
+ @overload # ?-d
2280
+ def __iter__ (self , / ) -> Iterator [Any ]: ...
2278
2281
2279
2282
# The last overload is for catching recursive objects whose
2280
2283
# nesting is too deep.
0 commit comments