-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathabc.pyi
More file actions
58 lines (53 loc) · 2.27 KB
/
abc.pyi
File metadata and controls
58 lines (53 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import sys
from _typeshed import StrPath
from abc import ABCMeta, abstractmethod
from collections.abc import Iterator
from io import BufferedReader
from typing import IO, Any, Literal, Protocol, overload, runtime_checkable
from typing_extensions import deprecated
if sys.version_info >= (3, 11):
@deprecated("Deprecated since Python 3.12. Use `importlib.resources.abc.TraversableResources` instead.")
class ResourceReader(metaclass=ABCMeta):
@abstractmethod
def open_resource(self, resource: str) -> IO[bytes]: ...
@abstractmethod
def resource_path(self, resource: str) -> str: ...
@abstractmethod
def is_resource(self, path: str) -> bool: ...
@abstractmethod
def contents(self) -> Iterator[str]: ...
@runtime_checkable
class Traversable(Protocol):
@abstractmethod
def is_dir(self) -> bool: ...
@abstractmethod
def is_file(self) -> bool: ...
@abstractmethod
def iterdir(self) -> Iterator[Traversable]: ...
@abstractmethod
def joinpath(self, *descendants: StrPath) -> Traversable: ...
# The documentation and runtime protocol allows *args, **kwargs arguments,
# but this would mean that all implementers would have to support them,
# which is not the case.
@overload
@abstractmethod
def open(self, mode: Literal["r"] = "r", *, encoding: str | None = None, errors: str | None = None) -> IO[str]: ...
@overload
@abstractmethod
def open(self, mode: Literal["rb"]) -> IO[bytes]: ...
@property
@abstractmethod
def name(self) -> str: ...
def __truediv__(self, child: StrPath, /) -> Traversable: ...
@abstractmethod
def read_bytes(self) -> bytes: ...
@abstractmethod
def read_text(self, encoding: str | None = None) -> str: ...
class TraversableResources(ResourceReader):
@abstractmethod
def files(self) -> Traversable: ...
def open_resource(self, resource: str) -> BufferedReader: ...
def resource_path(self, resource: Any) -> str: ...
def is_resource(self, path: str) -> bool: ...
def contents(self) -> Iterator[str]: ...
__all__ = ["ResourceReader", "Traversable", "TraversableResources"]