Skip to content

Commit 7d77682

Browse files
committed
TYP: Make the type parameter of numpy.flatiter covariant
1 parent abeca76 commit 7d77682

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

numpy/__init__.pyi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ test: PytestTester
641641
def show_config() -> None: ...
642642

643643
_NdArraySubClass = TypeVar("_NdArraySubClass", bound=NDArray[Any])
644+
_NdArraySubClass_co = TypeVar("_NdArraySubClass_co", bound=NDArray[Any], covariant=True)
644645
_DTypeScalar_co = TypeVar("_DTypeScalar_co", covariant=True, bound=generic)
645646
_ByteOrder: TypeAlias = L["S", "<", ">", "=", "|", "L", "B", "N", "I", "little", "big", "native"]
646647

@@ -906,15 +907,15 @@ _ArrayLikeInt: TypeAlias = (
906907
_FlatIterSelf = TypeVar("_FlatIterSelf", bound=flatiter[Any])
907908

908909
@final
909-
class flatiter(Generic[_NdArraySubClass]):
910+
class flatiter(Generic[_NdArraySubClass_co]):
910911
__hash__: ClassVar[None]
911912
@property
912-
def base(self) -> _NdArraySubClass: ...
913+
def base(self) -> _NdArraySubClass_co: ...
913914
@property
914915
def coords(self) -> _Shape: ...
915916
@property
916917
def index(self) -> int: ...
917-
def copy(self) -> _NdArraySubClass: ...
918+
def copy(self) -> _NdArraySubClass_co: ...
918919
def __iter__(self: _FlatIterSelf) -> _FlatIterSelf: ...
919920
def __next__(self: flatiter[NDArray[_ScalarType]]) -> _ScalarType: ...
920921
def __len__(self) -> int: ...
@@ -927,7 +928,7 @@ class flatiter(Generic[_NdArraySubClass]):
927928
def __getitem__(
928929
self,
929930
key: _ArrayLikeInt | slice | ellipsis | tuple[_ArrayLikeInt | slice | ellipsis],
930-
) -> _NdArraySubClass: ...
931+
) -> _NdArraySubClass_co: ...
931932
# TODO: `__setitem__` operates via `unsafe` casting rules, and can
932933
# thus accept any type accepted by the relevant underlying `np.generic`
933934
# constructor.

0 commit comments

Comments
 (0)