_typing.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from __future__ import annotations
  2. import os
  3. import sys
  4. from collections.abc import Sequence
  5. from typing import TYPE_CHECKING, Any, Protocol, TypeVar, Union
  6. if TYPE_CHECKING:
  7. from numbers import _IntegralLike as IntegralLike
  8. try:
  9. import numpy.typing as npt
  10. NumpyArray = npt.NDArray[Any] # requires numpy>=1.21
  11. except (ImportError, AttributeError):
  12. pass
  13. if sys.version_info >= (3, 13):
  14. from types import CapsuleType
  15. else:
  16. CapsuleType = object
  17. if sys.version_info >= (3, 12):
  18. from collections.abc import Buffer
  19. else:
  20. Buffer = Any
  21. if sys.version_info >= (3, 10):
  22. from typing import TypeGuard
  23. else:
  24. try:
  25. from typing_extensions import TypeGuard
  26. except ImportError:
  27. class TypeGuard: # type: ignore[no-redef]
  28. def __class_getitem__(cls, item: Any) -> type[bool]:
  29. return bool
  30. Coords = Union[Sequence[float], Sequence[Sequence[float]]]
  31. _T_co = TypeVar("_T_co", covariant=True)
  32. class SupportsRead(Protocol[_T_co]):
  33. def read(self, length: int = ..., /) -> _T_co: ...
  34. StrOrBytesPath = Union[str, bytes, os.PathLike[str], os.PathLike[bytes]]
  35. __all__ = ["Buffer", "IntegralLike", "StrOrBytesPath", "SupportsRead", "TypeGuard"]