summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorBas van Beek <b.f.van.beek@vu.nl>2022-01-27 13:50:56 +0100
committerBas van Beek <b.f.van.beek@vu.nl>2022-01-27 14:24:38 +0100
commit2b498702c1b281a75675b5b76b665f1dd873d7dd (patch)
treec36cc3ed4659d9a9b9f3860427325930909c40fc /numpy
parent1737a79dfa00894ef3fa48b556540daff05300e8 (diff)
downloadnumpy-2b498702c1b281a75675b5b76b665f1dd873d7dd.tar.gz
MAINT: Add annotations for `flatiter.__setitem__`
Diffstat (limited to 'numpy')
-rw-r--r--numpy/__init__.pyi9
-rw-r--r--numpy/typing/tests/data/reveal/flatiter.pyi4
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"