1 from abc import ABCMeta, abstractmethod
\r
5 from typing import Any, IO, Iterator, Mapping, Optional, Sequence, Tuple, Union
\r
7 # Loader is exported from this module, but for circular import reasons
\r
8 # exists in its own stub file (with ModuleSpec and ModuleType).
\r
9 from _importlib_modulespec import Loader as Loader # Exported
\r
11 from _importlib_modulespec import ModuleSpec
\r
13 _Path = Union[bytes, str]
\r
15 class Finder(metaclass=ABCMeta):
\r
17 # Technically this class defines the following method, but its subclasses
\r
18 # in this module violate its signature. Since this class is deprecated, it's
\r
19 # easier to simply ignore that this method exists.
\r
21 # def find_module(self, fullname: str,
\r
22 # path: Optional[Sequence[_Path]] = ...) -> Optional[Loader]: ...
\r
24 class ResourceLoader(Loader):
\r
26 def get_data(self, path: _Path) -> bytes: ...
\r
28 class InspectLoader(Loader):
\r
29 def is_package(self, fullname: str) -> bool: ...
\r
30 def get_code(self, fullname: str) -> Optional[types.CodeType]: ...
\r
31 def load_module(self, fullname: str) -> types.ModuleType: ...
\r
33 def get_source(self, fullname: str) -> Optional[str]: ...
\r
34 def exec_module(self, module: types.ModuleType) -> None: ...
\r
35 if sys.version_info < (3, 5):
\r
36 def source_to_code(self, data: Union[bytes, str],
\r
37 path: str = ...) -> types.CodeType: ...
\r
40 def source_to_code(data: Union[bytes, str],
\r
41 path: str = ...) -> types.CodeType: ...
\r
43 class ExecutionLoader(InspectLoader):
\r
45 def get_filename(self, fullname: str) -> _Path: ...
\r
46 def get_code(self, fullname: str) -> Optional[types.CodeType]: ...
\r
48 class SourceLoader(ResourceLoader, ExecutionLoader, metaclass=ABCMeta):
\r
49 def path_mtime(self, path: _Path) -> Union[int, float]: ...
\r
50 def set_data(self, path: _Path, data: bytes) -> None: ...
\r
51 def get_source(self, fullname: str) -> Optional[str]: ...
\r
52 def path_stats(self, path: _Path) -> Mapping[str, Any]: ...
\r
55 class MetaPathFinder(Finder):
\r
56 def find_module(self, fullname: str,
\r
57 path: Optional[Sequence[_Path]]) -> Optional[Loader]:
\r
59 def invalidate_caches(self) -> None: ...
\r
60 # Not defined on the actual class, but expected to exist.
\r
62 self, fullname: str, path: Optional[Sequence[_Path]],
\r
63 target: Optional[types.ModuleType] = ...
\r
64 ) -> Optional[ModuleSpec]:
\r
67 class PathEntryFinder(Finder):
\r
68 def find_module(self, fullname: str) -> Optional[Loader]: ...
\r
71 ) -> Tuple[Optional[Loader], Sequence[_Path]]: ...
\r
72 def invalidate_caches(self) -> None: ...
\r
73 # Not defined on the actual class, but expected to exist.
\r
75 self, fullname: str,
\r
76 target: Optional[types.ModuleType] = ...
\r
77 ) -> Optional[ModuleSpec]: ...
\r
79 class FileLoader(ResourceLoader, ExecutionLoader, metaclass=ABCMeta):
\r
80 name = ... # type: str
\r
81 path = ... # type: _Path
\r
82 def __init__(self, fullname: str, path: _Path) -> None: ...
\r
83 def get_data(self, path: _Path) -> bytes: ...
\r
84 def get_filename(self, fullname: str) -> _Path: ...
\r
86 if sys.version_info >= (3, 7):
\r
87 _PathLike = Union[bytes, str, os.PathLike[Any]]
\r
89 class ResourceReader(metaclass=ABCMeta):
\r
91 def open_resource(self, resource: _PathLike) -> IO[bytes]: ...
\r
93 def resource_path(self, resource: _PathLike) -> str: ...
\r
95 def is_resource(self, name: str) -> bool: ...
\r
97 def contents(self) -> Iterator[str]: ...
\r