_typing.py 851 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. from __future__ import annotations
  2. import os
  3. import sys
  4. from typing import Any, Protocol, Sequence, TypeVar, Union
  5. try:
  6. import numpy.typing as npt
  7. NumpyArray = npt.NDArray[Any]
  8. except ImportError:
  9. pass
  10. if sys.version_info >= (3, 10):
  11. from typing import TypeGuard
  12. else:
  13. try:
  14. from typing_extensions import TypeGuard
  15. except ImportError:
  16. class TypeGuard: # type: ignore[no-redef]
  17. def __class_getitem__(cls, item: Any) -> type[bool]:
  18. return bool
  19. Coords = Union[Sequence[float], Sequence[Sequence[float]]]
  20. _T_co = TypeVar("_T_co", covariant=True)
  21. class SupportsRead(Protocol[_T_co]):
  22. def read(self, __length: int = ...) -> _T_co: ...
  23. StrOrBytesPath = Union[str, bytes, "os.PathLike[str]", "os.PathLike[bytes]"]
  24. __all__ = ["TypeGuard", "StrOrBytesPath", "SupportsRead"]