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