Skip to content

Commit 8f3350c

Browse files
committed
expand importlib
1 parent 292447b commit 8f3350c

File tree

6 files changed

+352
-9
lines changed

6 files changed

+352
-9
lines changed

stdlib/3/importlib.pyi

Lines changed: 0 additions & 9 deletions
This file was deleted.

stdlib/3/importlib/__init__.pyi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Stubs for importlib (Python 3.4)
2+
3+
from ._bootstrap import __import__ as __import__
4+
5+
from typing import Optional
6+
from types import ModuleType
7+
8+
def invalidate_caches() -> None: ...
9+
def import_module(name: str, package: Optional[str] = ...) -> ModuleType: ...
10+
def reload(module: ModuleType) -> ModuleType: ...

stdlib/3/importlib/_bootstrap.pyi

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
# Stubs for importlib._bootstrap (Python 3.4)
2+
3+
from importlib.abc import Loader
4+
5+
from typing import (
6+
Any, Optional, Sequence, Callable, Iterator, Tuple, Iterable, Mapping, Union
7+
)
8+
from types import TracebackType, ModuleType, CodeType
9+
import _thread
10+
from ast import AST
11+
12+
class _ManageReload:
13+
def __init__(self, name: str) -> None: ...
14+
def __enter__(self) -> None: ...
15+
def __exit__(self, exc_type: Optional[type], exc_value:
16+
Optional[BaseException], traceback: TracebackType) \
17+
-> Optional[bool]: ...
18+
19+
class _DeadlockError(RuntimeError): ...
20+
21+
class _ModuleLock:
22+
lock = ... # type: _thread.LockType
23+
wakeup = ... # type: _thread.LockType
24+
name = ... # type: str
25+
owner = ... # type: Optional[int]
26+
count = ... # type: int
27+
waiters = ... # type: int
28+
def __init__(self, name: str) -> None: ...
29+
def has_deadlock(self) -> bool: ...
30+
def acquire(self) -> None: ...
31+
def release(self) -> None: ...
32+
33+
class _DummyModuleLock:
34+
name = ... # type: str
35+
count = ... # type: int
36+
def __init__(self, name: str) -> None: ...
37+
def acquire(self) -> None: ...
38+
def release(self) -> None: ...
39+
40+
class _ModuleLockManager:
41+
def __init__(self, name: str) -> None: ...
42+
def __enter__(self) -> None: ...
43+
def __exit__(self, exc_type: Optional[type], exc_value:
44+
Optional[BaseException], traceback: TracebackType) \
45+
-> Optional[bool]: ...
46+
47+
MAGIC_NUMBER = ... # type: bytes
48+
SOURCE_SUFFIXES = ... # type: List[str]
49+
DEBUG_BYTECODE_SUFFIXES = ... # type: List[str]
50+
OPTIMIZED_BYTECODE_SUFFIXES = ... # type: List[str]
51+
52+
def cache_from_source(path: str, debug_override: Optional[bool] = ...) -> str: ...
53+
def source_from_cache(path: str) -> str: ...
54+
def decode_source(source_bytes: bytes) -> str: ...
55+
56+
class _installed_safely:
57+
def __init__(self, module: ModuleType) -> None: ...
58+
def __enter__(self) -> None: ...
59+
def __exit__(self, exc_type: Optional[type], exc_value:
60+
Optional[BaseException], traceback: TracebackType) \
61+
-> Optional[bool]: ...
62+
63+
# TODO find real type of loader_state
64+
class ModuleSpec:
65+
name = ... # type: str
66+
loader = ... # type: Loader
67+
origin = ... # type: str
68+
loader_state = ... # type: Optional[Any]
69+
submodule_search_locations = ... # type: Sequence[str]
70+
def __init__(self, name: str, loader: Loader, *,
71+
origin: Optional[str] = ..., loader_state: Optional[Any] = ...,
72+
is_package: Optional[bool] = ...) -> None: ...
73+
def __eq__(self, other: Any) -> bool: ...
74+
@property
75+
def cached(self) -> Optional[str]: ...
76+
@cached.setter
77+
def cached(self, cached: Optional[str]) -> None: ...
78+
@property
79+
def parent(self) -> str: ...
80+
@property
81+
def has_location(self) -> bool: ...
82+
@has_location.setter
83+
def has_location(self, value: bool) -> None: ...
84+
85+
def spec_from_loader(name: str, loader: Loader, *, origin: Optional[str] = ...,
86+
is_package: Optional[bool] = ...) -> ModuleSpec: ...
87+
def spec_from_file_location(name: str, location: Optional[str] = ..., *,
88+
loader: Optional[Loader] = ...,
89+
submodule_search_locations: List[str] = ...) \
90+
-> ModuleSpec: ...
91+
92+
class _SpecMethods:
93+
spec = ... # type: ModuleSpec
94+
def __init__(self, spec: ModuleSpec) -> None: ...
95+
def module_repr(self) -> str: ...
96+
def init_module_attrs(self, module: ModuleType, *, _override: bool = ...,
97+
_force_name: bool = ...) -> None: ...
98+
def create(self) -> ModuleType: ...
99+
def exec(self, module: ModuleType) -> ModuleType: ...
100+
def load(self) -> ModuleType: ...
101+
102+
# TODO find real type of target
103+
class BuiltinImporter:
104+
@staticmethod
105+
def module_repr(module: ModuleType) -> str: ...
106+
@classmethod
107+
def find_spec(cls, fullname: str, path: Optional[str] = ...,
108+
target: Optional[Any] = ...) -> Optional[ModuleSpec]: ...
109+
@classmethod
110+
def find_module(cls, fullname: str, path: Optional[str] = ...) \
111+
-> Optional[Loader]: ...
112+
@classmethod
113+
def load_module(cls, fullname: str) -> ModuleType: ...
114+
@classmethod
115+
def get_code(cls, fullname: str) -> None: ...
116+
@classmethod
117+
def get_source(cls, fullname: str) -> None: ...
118+
@classmethod
119+
def is_package(cls, fullname: str) -> bool: ...
120+
121+
class FrozenImporter:
122+
@staticmethod
123+
def module_repr(module: ModuleType) -> str: ...
124+
@classmethod
125+
def find_spec(cls, fullname: str, path: Optional[str] = ...,
126+
target: Optional[Any] = ...) -> Optional[ModuleSpec]: ...
127+
@classmethod
128+
def find_module(cls, fullname: str, path: Optional[str] = ...) \
129+
-> Optional[Loader]: ...
130+
@staticmethod
131+
def exec_module(module: ModuleType) -> None: ...
132+
@classmethod
133+
def load_module(cls, fullname: str) -> ModuleType: ...
134+
@classmethod
135+
def get_code(cls, fullname: str) -> CodeType: ...
136+
@classmethod
137+
def get_source(cls, fullname: str) -> None: ...
138+
@classmethod
139+
def is_package(cls, fullname: str) -> bool: ...
140+
141+
class WindowsRegistryFinder:
142+
REGISTRY_KEY = ... # type: str
143+
REGISTRY_KEY_DEBUG = ... # type: str
144+
DEBUG_BUILD = ... # type: bool
145+
@classmethod
146+
def find_spec(cls, fullname: str, path: Optional[str] = ...,
147+
target: Optional[Any] = ...) -> Optional[ModuleSpec]: ...
148+
@classmethod
149+
def find_module(cls, fullname: str, path: Optional[str] = ...) \
150+
-> Optional[Loader]: ...
151+
152+
class _LoaderBasics:
153+
def is_package(cls, fullname: str) -> bool: ...
154+
def exec_module(module: ModuleType) -> bool: ...
155+
# TODO should be an object
156+
def load_module(self, fullname: str) -> ModuleType: ...
157+
158+
class SourceLoader(_LoaderBasics):
159+
def path_mtime(self, path: str) -> int: ...
160+
def path_stats(self, path: str) -> Dict[str, int]: ...
161+
def set_data(self, path: str, data: bytes) -> None: ...
162+
def get_source(self, fullname: str) -> str: ...
163+
def source_to_code(self, data: Union[str, bytes, AST], path: str, *,
164+
_optimize: int = ...) -> CodeType: ...
165+
def get_code(self, fullname: str) -> CodeType: ...
166+
167+
class FileLoader:
168+
name = ... # type: str
169+
path = ... # type: str
170+
def __init__(self, fullname: str, path: str) -> None: ...
171+
def __eq__(self, other: Any) -> bool: ...
172+
def __hash__(self) -> int: ...
173+
def load_module(self, fullname: str) -> ModuleType: ...
174+
def get_filename(self, fullname: str) -> str: ...
175+
def get_data(self, path: str) -> bytes: ...
176+
177+
class SourceFileLoader(FileLoader, SourceLoader):
178+
def set_data(self, path: str, data: bytes, *, _mode: int = ...) -> None: ...
179+
180+
class SourcelessFileLoader(FileLoader, _LoaderBasics):
181+
def get_code(self, fullname: str) -> CodeType: ...
182+
def get_source(self, fullname: str) -> str: ...
183+
184+
EXTENSION_SUFFIXES = ... # type: List[str]
185+
186+
class ExtensionFileLoader:
187+
name = ... # type: str
188+
path = ... # type: str
189+
def __init__(self, name: str, path: List[str]) -> None: ...
190+
def __eq__(self, other: Any) -> bool: ...
191+
def __hash__(self) -> int: ...
192+
def load_module(self, fullname: str) -> ModuleType: ...
193+
def is_package(cls, fullname: str) -> bool: ...
194+
def get_code(self, fullname: str) -> None: ...
195+
def get_source(self, fullname: str) -> None: ...
196+
def get_filename(self, fullname: str) -> str: ...
197+
198+
class _NamespacePath:
199+
def __init__(self, name: str, path: str,
200+
path_finder: Callable[[str, Tuple[str]], ModuleSpec]) \
201+
-> None: ...
202+
def __iter__(self) -> Iterator[str]: ...
203+
def __len__(self) -> int: ...
204+
def __contains__(self, item: str) -> bool: ...
205+
def append(self, item: str) -> None: ...
206+
207+
class _NamespaceLoader:
208+
def __init__(self, name: str, path: str,
209+
path_finder: Callable[[str, Tuple[str]], ModuleSpec]) \
210+
-> None: ...
211+
@classmethod
212+
def module_repr(self) -> str: ...
213+
def is_package(cls, fullname: str) -> bool: ...
214+
def get_source(self, fullname: str) -> None: ...
215+
def get_code(self, fullname: str) -> None: ...
216+
def exec_module(module: ModuleType) -> None: ...
217+
def load_module(self, fullname: str) -> ModuleType: ...
218+
219+
class PathFinder:
220+
@classmethod
221+
def invalidate_caches(cls) -> None: ...
222+
@classmethod
223+
def find_spec(cls, fullname: str, path: Optional[str] = ...,
224+
target: Optional[Any] = ...) -> Optional[ModuleSpec]: ...
225+
@classmethod
226+
def find_module(cls, fullname: str, path: Optional[str] = ...) \
227+
-> Optional[Loader]: ...
228+
229+
# TODO find real type of target
230+
class FileFinder:
231+
path = ... # type: str
232+
def __init__(self, path: str,
233+
*loader_details: Tuple[Loader, Iterable[str]]) -> None: ...
234+
def invalidate_caches(self) -> None: ...
235+
# TODO should be an object
236+
def find_module(cls, fullname: str, path: Optional[str] = ...) \
237+
-> Optional[Loader]: ...
238+
def find_loader(self, fullname: str) -> Tuple[Optional[Loader], List[str]]:
239+
...
240+
def find_spec(self, fullname: str, target: Optional[Any] = ...) \
241+
-> Optional[ModuleSpec]: ...
242+
@classmethod
243+
def path_hook(cls, *loader_details: Tuple[Loader, Iterable[str]]) \
244+
-> Callable[[str], 'FileFinder']: ...
245+
246+
class _ImportLockContext:
247+
def __enter__(self) -> None: ...
248+
def __exit__(self, exc_type: Optional[type], exc_value:
249+
Optional[BaseException], traceback: TracebackType) \
250+
-> Optional[bool]: ...
251+
252+
def _calc___package__(globals: Mapping[str, Optional[str]]) -> str: ...
253+
# TODO find real type of locals
254+
def __import__(name: str, globals: Optional[Mapping[str, Optional[str]]] = ...,
255+
locals: Optional[Any] = ..., fromlist: List[str] = ...,
256+
level: int = ...) -> ModuleType: ...
257+
258+
BYTECODE_SUFFIXES = ... # type: str

stdlib/3/importlib/abc.pyi

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Stubs for importlib.abc (Python 3.4)
2+
3+
import importlib._bootstrap as _bootstrap
4+
5+
from typing import Any, Optional, Tuple, List, Callable, Union
6+
from types import ModuleType, CodeType
7+
from ast import AST
8+
from importlib._bootstrap import ModuleSpec
9+
10+
class Finder:
11+
def find_module(self, fullname: str, path: Optional[str]) -> Optional[Loader]: ...
12+
13+
class MetaPathFinder(Finder):
14+
def invalidate_caches(self) -> None: ...
15+
16+
# TODO find real type of return of find_loader
17+
class PathEntryFinder(Finder):
18+
def find_loader(self, fullname: str) -> Tuple[Loader,List[Any]]: ...
19+
find_module = ... # type: Callable[[str], Loader]
20+
def invalidate_caches(self) -> None: ...
21+
22+
class Loader:
23+
def create_module(self, spec: ModuleSpec) -> Optional[ModuleType]: ...
24+
def load_module(self, fullname: str) -> ModuleType: ...
25+
def module_repr(self, module: ModuleType) -> str: ...
26+
27+
class ResourceLoader(Loader):
28+
def get_data(self, path: str) -> bytes: ...
29+
30+
# source can either be a normal string, a byte string, or an AST object.
31+
class InspectLoader(Loader):
32+
def is_package(self, fullname: str) -> bool: ...
33+
def get_code(self, fullname: str) -> Optional[CodeType]: ...
34+
def get_source(self, fullname: str) -> str: ...
35+
def source_to_code(self, data: Union[str, bytes, AST], path: str, *,
36+
_optimize: int = ...) -> CodeType: ...
37+
# TODO should be an object
38+
def exec_module(module: ModuleType) -> bool: ...
39+
# TODO should be an object
40+
def load_module(self, fullname: str) -> ModuleType: ...
41+
42+
class ExecutionLoader(InspectLoader):
43+
def get_filename(self, fullname: str) -> str: ...
44+
def get_code(self, fullname: str) -> CodeType: ...
45+
46+
class FileLoader(_bootstrap.FileLoader, ResourceLoader, ExecutionLoader): ...
47+
48+
class SourceLoader(_bootstrap.SourceLoader, ResourceLoader, ExecutionLoader):
49+
...

stdlib/3/importlib/machinery.pyi

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Stubs for importlib.machinery (Python 3.4)
2+
3+
from ._bootstrap import SOURCE_SUFFIXES as SOURCE_SUFFIXES, DEBUG_BYTECODE_SUFFIXES as DEBUG_BYTECODE_SUFFIXES, OPTIMIZED_BYTECODE_SUFFIXES as OPTIMIZED_BYTECODE_SUFFIXES, BYTECODE_SUFFIXES as BYTECODE_SUFFIXES, EXTENSION_SUFFIXES as EXTENSION_SUFFIXES
4+
from ._bootstrap import ModuleSpec as ModuleSpec
5+
from ._bootstrap import BuiltinImporter as BuiltinImporter
6+
from ._bootstrap import FrozenImporter as FrozenImporter
7+
from ._bootstrap import WindowsRegistryFinder as WindowsRegistryFinder
8+
from ._bootstrap import PathFinder as PathFinder
9+
from ._bootstrap import FileFinder as FileFinder
10+
from ._bootstrap import SourceFileLoader as SourceFileLoader
11+
from ._bootstrap import SourcelessFileLoader as SourcelessFileLoader
12+
from ._bootstrap import ExtensionFileLoader as ExtensionFileLoader
13+
14+
from typing import List
15+
16+
def all_suffixes() -> List[str]: ...

stdlib/3/importlib/util.pyi

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Stubs for importlib.util (Python 3.4)
2+
3+
from ._bootstrap import MAGIC_NUMBER as MAGIC_NUMBER
4+
from ._bootstrap import cache_from_source as cache_from_source
5+
from ._bootstrap import decode_source as decode_source
6+
from ._bootstrap import source_from_cache as source_from_cache
7+
from ._bootstrap import spec_from_loader as spec_from_loader
8+
from ._bootstrap import spec_from_file_location as spec_from_file_location
9+
10+
from typing import Optional, Callable
11+
from ._bootstrap import ModuleSpec
12+
from types import ModuleType
13+
14+
def resolve_name(name: str, package: Optional[str]) -> str: ...
15+
def find_spec(name: str, package: Optional[str] = ...) -> Optional[ModuleSpec]: ...
16+
def set_package(fxn: Callable[..., ModuleType]) -> Callable[..., ModuleType]: ...
17+
def set_loader(fxn: Callable[..., ModuleType]) -> Callable[..., ModuleType]: ...
18+
def module_for_loader(fxn: Callable[..., ModuleType]) \
19+
-> Callable[..., ModuleType]: ...

0 commit comments

Comments
 (0)