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