diff options
| author | Matti Picus <matti.picus@gmail.com> | 2021-07-27 14:42:44 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-27 14:42:44 +0300 |
| commit | b908da64dd4fa8dc70932f51202f9701db4cc868 (patch) | |
| tree | 08f5842059f26dc9d84bb2a5a371234b7b9d743a /numpy | |
| parent | 83377c70a3dc49a7f3200c85d9736b346c42760f (diff) | |
| parent | 11253f4342904285abdd7575d3acc40f9ef3ed2f (diff) | |
| download | numpy-b908da64dd4fa8dc70932f51202f9701db4cc868.tar.gz | |
Merge pull request #19554 from MatthieuDartiailh/nditer-typing
MAINT: add missing dunder method to nditer type hints
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/__init__.pyi | 16 | ||||
| -rw-r--r-- | numpy/typing/tests/data/reveal/nditer.py | 19 |
2 files changed, 35 insertions, 0 deletions
diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi index 6e27e6047..5cef4639b 100644 --- a/numpy/__init__.pyi +++ b/numpy/__init__.pyi @@ -173,6 +173,7 @@ from typing import ( Generic, IO, Iterable, + Iterator, List, Mapping, NoReturn, @@ -780,6 +781,21 @@ class nditer: buffersize: Any = ..., ) -> Any: ... def __getattr__(self, key: str) -> Any: ... + def __enter__(self) -> nditer: ... + def __exit__( + self, + exc_type: None | Type[BaseException], + exc_value: None | BaseException, + traceback: None | TracebackType, + ) -> None: ... + def __iter__(self) -> Iterator[Any]: ... + def __next__(self) -> Any: ... + def __len__(self) -> int: ... + def __copy__(self) -> nditer: ... + def __getitem__(self, index: SupportsIndex | slice) -> Any: ... + def __setitem__(self, index: SupportsIndex | slice, value: Any) -> None: ... + def __delitem__(self, key: SupportsIndex | slice) -> None: ... + class poly1d: def __init__( diff --git a/numpy/typing/tests/data/reveal/nditer.py b/numpy/typing/tests/data/reveal/nditer.py new file mode 100644 index 000000000..de2a4b5ed --- /dev/null +++ b/numpy/typing/tests/data/reveal/nditer.py @@ -0,0 +1,19 @@ +import copy +import numpy as np + +nditer_obj: np.nditer + +with nditer_obj as context: + reveal_type(context) # E: numpy.nditer + +reveal_type(len(nditer_obj)) # E: builtins.int +reveal_type(copy.copy(nditer_obj)) # E: numpy.nditer +reveal_type(next(nditer_obj)) # E: Any +reveal_type(iter(nditer_obj)) # E: typing.Iterator[Any] +reveal_type(nditer_obj[1]) # E: Any +reveal_type(nditer_obj[1:5]) # E: Any + +nditer_obj[1] = 1 +nditer_obj[1:5] = 1 +del nditer_obj[1] +del nditer_obj[1:5] |
