diff options
-rw-r--r-- | numpy/__init__.pyi | 9 | ||||
-rw-r--r-- | numpy/typing/tests/data/reveal/flatiter.pyi | 4 |
2 files changed, 13 insertions, 0 deletions
diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi index f656e8f2f..e18d074de 100644 --- a/numpy/__init__.pyi +++ b/numpy/__init__.pyi @@ -951,6 +951,15 @@ class flatiter(Generic[_NdArraySubClass]): self, key: _ArrayLikeInt | slice | ellipsis | tuple[_ArrayLikeInt | slice | ellipsis], ) -> _NdArraySubClass: ... + # TODO: `__setitem__` operates via `unsafe` casting rules, and can + # thus accept any type accepted by the relevant underlying `np.generic` + # constructor. + # This means that `value` must in reality be a supertype of `npt.ArrayLike`. + def __setitem__( + self, + key: _ArrayLikeInt | slice | ellipsis | tuple[_ArrayLikeInt | slice | ellipsis], + value: Any, + ) -> None: ... @overload def __array__(self: flatiter[ndarray[Any, _DType]], dtype: None = ..., /) -> ndarray[Any, _DType]: ... @overload diff --git a/numpy/typing/tests/data/reveal/flatiter.pyi b/numpy/typing/tests/data/reveal/flatiter.pyi index 61e8a3e91..9e7d6e545 100644 --- a/numpy/typing/tests/data/reveal/flatiter.pyi +++ b/numpy/typing/tests/data/reveal/flatiter.pyi @@ -17,3 +17,7 @@ reveal_type(a[(...,)]) # E: ndarray[Any, dtype[str_]] reveal_type(a[(0,)]) # E: str_ reveal_type(a.__array__()) # E: ndarray[Any, dtype[str_]] reveal_type(a.__array__(np.dtype(np.float64))) # E: ndarray[Any, dtype[{float64}]] +a[0] = "a" +a[:5] = "a" +a[...] = "a" +a[(...,)] = "a" |