Pillow/src/PIL/_typing.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

42 lines
973 B
Python
Raw Normal View History

from __future__ import annotations
2024-01-22 22:37:37 +03:00
import os
import sys
from collections.abc import Sequence
from typing import TYPE_CHECKING, Any, Protocol, TypeVar, Union
2024-06-21 13:41:22 +03:00
if TYPE_CHECKING:
try:
import numpy.typing as npt
2024-06-21 13:41:22 +03:00
NumpyArray = npt.NDArray[Any] # requires numpy>=1.21
except (ImportError, AttributeError):
pass
if sys.version_info >= (3, 10):
from typing import TypeGuard
else:
try:
from typing_extensions import TypeGuard
except ImportError:
class TypeGuard: # type: ignore[no-redef]
def __class_getitem__(cls, item: Any) -> type[bool]:
return bool
2024-02-05 23:49:43 +03:00
Coords = Union[Sequence[float], Sequence[Sequence[float]]]
2024-01-22 22:37:37 +03:00
_T_co = TypeVar("_T_co", covariant=True)
class SupportsRead(Protocol[_T_co]):
def read(self, __length: int = ...) -> _T_co: ...
2024-01-22 22:37:37 +03:00
StrOrBytesPath = Union[str, bytes, "os.PathLike[str]", "os.PathLike[bytes]"]
2024-02-10 12:47:32 +03:00
__all__ = ["TypeGuard", "StrOrBytesPath", "SupportsRead"]