_typing.py 1.2 KB

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