diff --git a/stdlib/3/importlib.pyi b/stdlib/3/importlib.pyi deleted file mode 100644 index 12cc79e6c86a..000000000000 --- a/stdlib/3/importlib.pyi +++ /dev/null @@ -1,9 +0,0 @@ -# Stubs for importlib - -# NOTE: These are incomplete! - -from typing import Any - -# TODO more precise type? -def import_module(name: str, package: str = ...) -> Any: ... -def invalidate_caches() -> None: ... diff --git a/stdlib/3/importlib/__init__.pyi b/stdlib/3/importlib/__init__.pyi new file mode 100644 index 000000000000..80aef26d8299 --- /dev/null +++ b/stdlib/3/importlib/__init__.pyi @@ -0,0 +1,10 @@ +# Stubs for importlib (Python 3.4) + +from ._bootstrap import __import__ as __import__ + +from typing import Optional +from types import ModuleType + +def invalidate_caches() -> None: ... +def import_module(name: str, package: Optional[str] = ...) -> ModuleType: ... +def reload(module: ModuleType) -> ModuleType: ... diff --git a/stdlib/3/importlib/_bootstrap.pyi b/stdlib/3/importlib/_bootstrap.pyi new file mode 100644 index 000000000000..b37756832eae --- /dev/null +++ b/stdlib/3/importlib/_bootstrap.pyi @@ -0,0 +1,258 @@ +# Stubs for importlib._bootstrap (Python 3.4) + +from importlib.abc import Loader + +from typing import ( + Any, Optional, Sequence, Callable, Iterator, Tuple, Iterable, Mapping, Union +) +from types import TracebackType, ModuleType, CodeType +import _thread +from ast import AST + +class _ManageReload: + def __init__(self, name: str) -> None: ... + def __enter__(self) -> None: ... + def __exit__(self, exc_type: Optional[type], exc_value: + Optional[BaseException], traceback: TracebackType) \ + -> Optional[bool]: ... + +class _DeadlockError(RuntimeError): ... + +class _ModuleLock: + lock = ... # type: _thread.LockType + wakeup = ... # type: _thread.LockType + name = ... # type: str + owner = ... # type: Optional[int] + count = ... # type: int + waiters = ... # type: int + def __init__(self, name: str) -> None: ... + def has_deadlock(self) -> bool: ... + def acquire(self) -> None: ... + def release(self) -> None: ... + +class _DummyModuleLock: + name = ... # type: str + count = ... # type: int + def __init__(self, name: str) -> None: ... + def acquire(self) -> None: ... + def release(self) -> None: ... + +class _ModuleLockManager: + def __init__(self, name: str) -> None: ... + def __enter__(self) -> None: ... + def __exit__(self, exc_type: Optional[type], exc_value: + Optional[BaseException], traceback: TracebackType) \ + -> Optional[bool]: ... + +MAGIC_NUMBER = ... # type: bytes +SOURCE_SUFFIXES = ... # type: List[str] +DEBUG_BYTECODE_SUFFIXES = ... # type: List[str] +OPTIMIZED_BYTECODE_SUFFIXES = ... # type: List[str] + +def cache_from_source(path: str, debug_override: Optional[bool] = ...) -> str: ... +def source_from_cache(path: str) -> str: ... +def decode_source(source_bytes: bytes) -> str: ... + +class _installed_safely: + def __init__(self, module: ModuleType) -> None: ... + def __enter__(self) -> None: ... + def __exit__(self, exc_type: Optional[type], exc_value: + Optional[BaseException], traceback: TracebackType) \ + -> Optional[bool]: ... + +# TODO find real type of loader_state +class ModuleSpec: + name = ... # type: str + loader = ... # type: Loader + origin = ... # type: str + loader_state = ... # type: Optional[Any] + submodule_search_locations = ... # type: Sequence[str] + def __init__(self, name: str, loader: Loader, *, + origin: Optional[str] = ..., loader_state: Optional[Any] = ..., + is_package: Optional[bool] = ...) -> None: ... + def __eq__(self, other: Any) -> bool: ... + @property + def cached(self) -> Optional[str]: ... + @cached.setter + def cached(self, cached: Optional[str]) -> None: ... + @property + def parent(self) -> str: ... + @property + def has_location(self) -> bool: ... + @has_location.setter + def has_location(self, value: bool) -> None: ... + +def spec_from_loader(name: str, loader: Loader, *, origin: Optional[str] = ..., + is_package: Optional[bool] = ...) -> ModuleSpec: ... +def spec_from_file_location(name: str, location: Optional[str] = ..., *, + loader: Optional[Loader] = ..., + submodule_search_locations: List[str] = ...) \ + -> ModuleSpec: ... + +class _SpecMethods: + spec = ... # type: ModuleSpec + def __init__(self, spec: ModuleSpec) -> None: ... + def module_repr(self) -> str: ... + def init_module_attrs(self, module: ModuleType, *, _override: bool = ..., + _force_name: bool = ...) -> None: ... + def create(self) -> ModuleType: ... + def exec(self, module: ModuleType) -> ModuleType: ... + def load(self) -> ModuleType: ... + +# TODO find real type of target +class BuiltinImporter: + @staticmethod + def module_repr(module: ModuleType) -> str: ... + @classmethod + def find_spec(cls, fullname: str, path: Optional[str] = ..., + target: Optional[Any] = ...) -> Optional[ModuleSpec]: ... + @classmethod + def find_module(cls, fullname: str, path: Optional[str] = ...) \ + -> Optional[Loader]: ... + @classmethod + def load_module(cls, fullname: str) -> ModuleType: ... + @classmethod + def get_code(cls, fullname: str) -> None: ... + @classmethod + def get_source(cls, fullname: str) -> None: ... + @classmethod + def is_package(cls, fullname: str) -> bool: ... + +class FrozenImporter: + @staticmethod + def module_repr(module: ModuleType) -> str: ... + @classmethod + def find_spec(cls, fullname: str, path: Optional[str] = ..., + target: Optional[Any] = ...) -> Optional[ModuleSpec]: ... + @classmethod + def find_module(cls, fullname: str, path: Optional[str] = ...) \ + -> Optional[Loader]: ... + @staticmethod + def exec_module(module: ModuleType) -> None: ... + @classmethod + def load_module(cls, fullname: str) -> ModuleType: ... + @classmethod + def get_code(cls, fullname: str) -> CodeType: ... + @classmethod + def get_source(cls, fullname: str) -> None: ... + @classmethod + def is_package(cls, fullname: str) -> bool: ... + +class WindowsRegistryFinder: + REGISTRY_KEY = ... # type: str + REGISTRY_KEY_DEBUG = ... # type: str + DEBUG_BUILD = ... # type: bool + @classmethod + def find_spec(cls, fullname: str, path: Optional[str] = ..., + target: Optional[Any] = ...) -> Optional[ModuleSpec]: ... + @classmethod + def find_module(cls, fullname: str, path: Optional[str] = ...) \ + -> Optional[Loader]: ... + +class _LoaderBasics: + def is_package(cls, fullname: str) -> bool: ... + def exec_module(module: ModuleType) -> bool: ... + # TODO should be an object + def load_module(self, fullname: str) -> ModuleType: ... + +class SourceLoader(_LoaderBasics): + def path_mtime(self, path: str) -> int: ... + def path_stats(self, path: str) -> Dict[str, int]: ... + def set_data(self, path: str, data: bytes) -> None: ... + def get_source(self, fullname: str) -> str: ... + def source_to_code(self, data: Union[str, bytes, AST], path: str, *, + _optimize: int = ...) -> CodeType: ... + def get_code(self, fullname: str) -> CodeType: ... + +class FileLoader: + name = ... # type: str + path = ... # type: str + def __init__(self, fullname: str, path: str) -> None: ... + def __eq__(self, other: Any) -> bool: ... + def __hash__(self) -> int: ... + def load_module(self, fullname: str) -> ModuleType: ... + def get_filename(self, fullname: str) -> str: ... + def get_data(self, path: str) -> bytes: ... + +class SourceFileLoader(FileLoader, SourceLoader): + def set_data(self, path: str, data: bytes, *, _mode: int = ...) -> None: ... + +class SourcelessFileLoader(FileLoader, _LoaderBasics): + def get_code(self, fullname: str) -> CodeType: ... + def get_source(self, fullname: str) -> str: ... + +EXTENSION_SUFFIXES = ... # type: List[str] + +class ExtensionFileLoader: + name = ... # type: str + path = ... # type: str + def __init__(self, name: str, path: List[str]) -> None: ... + def __eq__(self, other: Any) -> bool: ... + def __hash__(self) -> int: ... + def load_module(self, fullname: str) -> ModuleType: ... + def is_package(cls, fullname: str) -> bool: ... + def get_code(self, fullname: str) -> None: ... + def get_source(self, fullname: str) -> None: ... + def get_filename(self, fullname: str) -> str: ... + +class _NamespacePath: + def __init__(self, name: str, path: str, + path_finder: Callable[[str, Tuple[str]], ModuleSpec]) \ + -> None: ... + def __iter__(self) -> Iterator[str]: ... + def __len__(self) -> int: ... + def __contains__(self, item: str) -> bool: ... + def append(self, item: str) -> None: ... + +class _NamespaceLoader: + def __init__(self, name: str, path: str, + path_finder: Callable[[str, Tuple[str]], ModuleSpec]) \ + -> None: ... + @classmethod + def module_repr(self) -> str: ... + def is_package(cls, fullname: str) -> bool: ... + def get_source(self, fullname: str) -> None: ... + def get_code(self, fullname: str) -> None: ... + def exec_module(module: ModuleType) -> None: ... + def load_module(self, fullname: str) -> ModuleType: ... + +class PathFinder: + @classmethod + def invalidate_caches(cls) -> None: ... + @classmethod + def find_spec(cls, fullname: str, path: Optional[str] = ..., + target: Optional[Any] = ...) -> Optional[ModuleSpec]: ... + @classmethod + def find_module(cls, fullname: str, path: Optional[str] = ...) \ + -> Optional[Loader]: ... + +# TODO find real type of target +class FileFinder: + path = ... # type: str + def __init__(self, path: str, + *loader_details: Tuple[Loader, Iterable[str]]) -> None: ... + def invalidate_caches(self) -> None: ... + # TODO should be an object + def find_module(cls, fullname: str, path: Optional[str] = ...) \ + -> Optional[Loader]: ... + def find_loader(self, fullname: str) -> Tuple[Optional[Loader], List[str]]: + ... + def find_spec(self, fullname: str, target: Optional[Any] = ...) \ + -> Optional[ModuleSpec]: ... + @classmethod + def path_hook(cls, *loader_details: Tuple[Loader, Iterable[str]]) \ + -> Callable[[str], 'FileFinder']: ... + +class _ImportLockContext: + def __enter__(self) -> None: ... + def __exit__(self, exc_type: Optional[type], exc_value: + Optional[BaseException], traceback: TracebackType) \ + -> Optional[bool]: ... + +def _calc___package__(globals: Mapping[str, Optional[str]]) -> str: ... +# TODO find real type of locals +def __import__(name: str, globals: Optional[Mapping[str, Optional[str]]] = ..., + locals: Optional[Any] = ..., fromlist: List[str] = ..., + level: int = ...) -> ModuleType: ... + +BYTECODE_SUFFIXES = ... # type: str diff --git a/stdlib/3/importlib/abc.pyi b/stdlib/3/importlib/abc.pyi new file mode 100644 index 000000000000..ff4955a13c4a --- /dev/null +++ b/stdlib/3/importlib/abc.pyi @@ -0,0 +1,49 @@ +# Stubs for importlib.abc (Python 3.4) + +import importlib._bootstrap as _bootstrap + +from typing import Any, Optional, Tuple, List, Callable, Union +from types import ModuleType, CodeType +from ast import AST +from importlib._bootstrap import ModuleSpec + +class Finder: + def find_module(self, fullname: str, path: Optional[str]) -> Optional[Loader]: ... + +class MetaPathFinder(Finder): + def invalidate_caches(self) -> None: ... + +# TODO find real type of return of find_loader +class PathEntryFinder(Finder): + def find_loader(self, fullname: str) -> Tuple[Loader,List[Any]]: ... + find_module = ... # type: Callable[[str], Loader] + def invalidate_caches(self) -> None: ... + +class Loader: + def create_module(self, spec: ModuleSpec) -> Optional[ModuleType]: ... + def load_module(self, fullname: str) -> ModuleType: ... + def module_repr(self, module: ModuleType) -> str: ... + +class ResourceLoader(Loader): + def get_data(self, path: str) -> bytes: ... + +# source can either be a normal string, a byte string, or an AST object. +class InspectLoader(Loader): + def is_package(self, fullname: str) -> bool: ... + def get_code(self, fullname: str) -> Optional[CodeType]: ... + def get_source(self, fullname: str) -> str: ... + def source_to_code(self, data: Union[str, bytes, AST], path: str, *, + _optimize: int = ...) -> CodeType: ... + # TODO should be an object + def exec_module(module: ModuleType) -> bool: ... + # TODO should be an object + def load_module(self, fullname: str) -> ModuleType: ... + +class ExecutionLoader(InspectLoader): + def get_filename(self, fullname: str) -> str: ... + def get_code(self, fullname: str) -> CodeType: ... + +class FileLoader(_bootstrap.FileLoader, ResourceLoader, ExecutionLoader): ... + +class SourceLoader(_bootstrap.SourceLoader, ResourceLoader, ExecutionLoader): + ... diff --git a/stdlib/3/importlib/machinery.pyi b/stdlib/3/importlib/machinery.pyi new file mode 100644 index 000000000000..89ff84ff57a8 --- /dev/null +++ b/stdlib/3/importlib/machinery.pyi @@ -0,0 +1,16 @@ +# Stubs for importlib.machinery (Python 3.4) + +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 +from ._bootstrap import ModuleSpec as ModuleSpec +from ._bootstrap import BuiltinImporter as BuiltinImporter +from ._bootstrap import FrozenImporter as FrozenImporter +from ._bootstrap import WindowsRegistryFinder as WindowsRegistryFinder +from ._bootstrap import PathFinder as PathFinder +from ._bootstrap import FileFinder as FileFinder +from ._bootstrap import SourceFileLoader as SourceFileLoader +from ._bootstrap import SourcelessFileLoader as SourcelessFileLoader +from ._bootstrap import ExtensionFileLoader as ExtensionFileLoader + +from typing import List + +def all_suffixes() -> List[str]: ... diff --git a/stdlib/3/importlib/util.pyi b/stdlib/3/importlib/util.pyi new file mode 100644 index 000000000000..d8c97d584b08 --- /dev/null +++ b/stdlib/3/importlib/util.pyi @@ -0,0 +1,19 @@ +# Stubs for importlib.util (Python 3.4) + +from ._bootstrap import MAGIC_NUMBER as MAGIC_NUMBER +from ._bootstrap import cache_from_source as cache_from_source +from ._bootstrap import decode_source as decode_source +from ._bootstrap import source_from_cache as source_from_cache +from ._bootstrap import spec_from_loader as spec_from_loader +from ._bootstrap import spec_from_file_location as spec_from_file_location + +from typing import Optional, Callable +from ._bootstrap import ModuleSpec +from types import ModuleType + +def resolve_name(name: str, package: Optional[str]) -> str: ... +def find_spec(name: str, package: Optional[str] = ...) -> Optional[ModuleSpec]: ... +def set_package(fxn: Callable[..., ModuleType]) -> Callable[..., ModuleType]: ... +def set_loader(fxn: Callable[..., ModuleType]) -> Callable[..., ModuleType]: ... +def module_for_loader(fxn: Callable[..., ModuleType]) \ + -> Callable[..., ModuleType]: ...