_arrayterator_impl.pyi 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # pyright: reportIncompatibleMethodOverride=false
  2. from collections.abc import Generator
  3. from types import EllipsisType
  4. from typing import Any, Final, TypeAlias, overload
  5. from typing_extensions import TypeVar
  6. import numpy as np
  7. __all__ = ["Arrayterator"]
  8. _ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], covariant=True)
  9. _DTypeT = TypeVar("_DTypeT", bound=np.dtype[Any])
  10. _DTypeT_co = TypeVar("_DTypeT_co", bound=np.dtype[Any], covariant=True)
  11. _ScalarT = TypeVar("_ScalarT", bound=np.generic)
  12. _AnyIndex: TypeAlias = EllipsisType | int | slice | tuple[EllipsisType | int | slice, ...]
  13. # NOTE: In reality `Arrayterator` does not actually inherit from `ndarray`,
  14. # but its ``__getattr__` method does wrap around the former and thus has
  15. # access to all its methods
  16. class Arrayterator(np.ndarray[_ShapeT_co, _DTypeT_co]):
  17. var: np.ndarray[_ShapeT_co, _DTypeT_co] # type: ignore[assignment]
  18. buf_size: Final[int | None]
  19. start: Final[list[int]]
  20. stop: Final[list[int]]
  21. step: Final[list[int]]
  22. @property # type: ignore[misc]
  23. def shape(self) -> _ShapeT_co: ...
  24. @property
  25. def flat(self: Arrayterator[Any, np.dtype[_ScalarT]]) -> Generator[_ScalarT]: ... # type: ignore[override]
  26. #
  27. def __init__(self, /, var: np.ndarray[_ShapeT_co, _DTypeT_co], buf_size: int | None = None) -> None: ...
  28. def __getitem__(self, index: _AnyIndex, /) -> Arrayterator[tuple[int, ...], _DTypeT_co]: ... # type: ignore[override]
  29. def __iter__(self) -> Generator[np.ndarray[tuple[int, ...], _DTypeT_co]]: ...
  30. #
  31. @overload # type: ignore[override]
  32. def __array__(self, /, dtype: None = None, copy: bool | None = None) -> np.ndarray[_ShapeT_co, _DTypeT_co]: ...
  33. @overload
  34. def __array__(self, /, dtype: _DTypeT, copy: bool | None = None) -> np.ndarray[_ShapeT_co, _DTypeT]: ...