diff --git a/stdlib/3/_importlib_modulespec.pyi b/stdlib/3/_importlib_modulespec.pyi index 4ce627836..74545aab7 100644 --- a/stdlib/3/_importlib_modulespec.pyi +++ b/stdlib/3/_importlib_modulespec.pyi @@ -9,36 +9,32 @@ from abc import ABCMeta import sys from typing import Any, Dict, List, Optional -if sys.version_info >= (3, 4): - class ModuleSpec: - def __init__(self, name: str, loader: Optional['Loader'], *, - origin: Optional[str] = ..., loader_state: Any = ..., - is_package: Optional[bool] = ...) -> None: ... - name = ... # type: str - loader = ... # type: Optional[Loader] - origin = ... # type: Optional[str] - submodule_search_locations = ... # type: Optional[List[str]] - loader_state = ... # type: Any - cached = ... # type: Optional[str] - parent = ... # type: Optional[str] - has_location = ... # type: bool +class ModuleSpec: + def __init__(self, name: str, loader: Optional['Loader'], *, + origin: Optional[str] = ..., loader_state: Any = ..., + is_package: Optional[bool] = ...) -> None: ... + name = ... # type: str + loader = ... # type: Optional[Loader] + origin = ... # type: Optional[str] + submodule_search_locations = ... # type: Optional[List[str]] + loader_state = ... # type: Any + cached = ... # type: Optional[str] + parent = ... # type: Optional[str] + has_location = ... # type: bool class ModuleType: __name__ = ... # type: str __file__ = ... # type: str __dict__ = ... # type: Dict[str, Any] - if sys.version_info >= (3, 4): - __loader__ = ... # type: Optional[Loader] - __package__ = ... # type: Optional[str] - __spec__ = ... # type: Optional[ModuleSpec] + __loader__ = ... # type: Optional[Loader] + __package__ = ... # type: Optional[str] + __spec__ = ... # type: Optional[ModuleSpec] def __init__(self, name: str, doc: Optional[str] = ...) -> None: ... class Loader(metaclass=ABCMeta): def load_module(self, fullname: str) -> ModuleType: ... - if sys.version_info >= (3, 3): - def module_repr(self, module: ModuleType) -> str: ... - if sys.version_info >= (3, 4): - def create_module(self, spec: ModuleSpec) -> Optional[ModuleType]: ... - # Not defined on the actual class for backwards-compatibility reasons, - # but expected in new code. - def exec_module(self, module: ModuleType) -> None: ... + def module_repr(self, module: ModuleType) -> str: ... + def create_module(self, spec: ModuleSpec) -> Optional[ModuleType]: ... + # Not defined on the actual class for backwards-compatibility reasons, + # but expected in new code. + def exec_module(self, module: ModuleType) -> None: ... diff --git a/stdlib/3/importlib/__init__.pyi b/stdlib/3/importlib/__init__.pyi index c3533f58c..78a81712d 100644 --- a/stdlib/3/importlib/__init__.pyi +++ b/stdlib/3/importlib/__init__.pyi @@ -11,10 +11,8 @@ def __import__(name: str, globals: Optional[Mapping[str, Any]] = ..., def import_module(name: str, package: Optional[str] = ...) -> types.ModuleType: ... -if sys.version_info >= (3, 3): - def find_loader(name: str, path: Optional[str] = ...) -> Optional[Loader]: ... +def find_loader(name: str, path: Optional[str] = ...) -> Optional[Loader]: ... - def invalidate_caches() -> None: ... +def invalidate_caches() -> None: ... -if sys.version_info >= (3, 4): - def reload(module: types.ModuleType) -> types.ModuleType: ... +def reload(module: types.ModuleType) -> types.ModuleType: ... diff --git a/stdlib/3/importlib/abc.pyi b/stdlib/3/importlib/abc.pyi index 00deb6832..e8bf33e5d 100644 --- a/stdlib/3/importlib/abc.pyi +++ b/stdlib/3/importlib/abc.pyi @@ -8,8 +8,7 @@ from typing import Any, IO, Iterator, Mapping, Optional, Sequence, Tuple, Union # exists in its own stub file (with ModuleSpec and ModuleType). from _importlib_modulespec import Loader as Loader # Exported -if sys.version_info >= (3, 4): - from _importlib_modulespec import ModuleSpec +from _importlib_modulespec import ModuleSpec _Path = Union[bytes, str] @@ -32,12 +31,11 @@ class InspectLoader(Loader): def load_module(self, fullname: str) -> types.ModuleType: ... @abstractmethod def get_source(self, fullname: str) -> Optional[str]: ... - if sys.version_info >= (3, 4): - def exec_module(self, module: types.ModuleType) -> None: ... - if sys.version_info[:2] == (3, 4): + def exec_module(self, module: types.ModuleType) -> None: ... + if sys.version_info < (3, 5): def source_to_code(self, data: Union[bytes, str], path: str = ...) -> types.CodeType: ... - elif sys.version_info >= (3, 5): + else: @staticmethod def source_to_code(data: Union[bytes, str], path: str = ...) -> types.CodeType: ... @@ -51,43 +49,39 @@ class SourceLoader(ResourceLoader, ExecutionLoader, metaclass=ABCMeta): def path_mtime(self, path: _Path) -> Union[int, float]: ... def set_data(self, path: _Path, data: bytes) -> None: ... def get_source(self, fullname: str) -> Optional[str]: ... - if sys.version_info >= (3, 3): - def path_stats(self, path: _Path) -> Mapping[str, Any]: ... + def path_stats(self, path: _Path) -> Mapping[str, Any]: ... -if sys.version_info >= (3, 3): - class MetaPathFinder(Finder): - def find_module(self, fullname: str, - path: Optional[Sequence[_Path]]) -> Optional[Loader]: - ... - def invalidate_caches(self) -> None: ... - if sys.version_info >= (3, 4): - # Not defined on the actual class, but expected to exist. - def find_spec( - self, fullname: str, path: Optional[Sequence[_Path]], - target: Optional[types.ModuleType] = ... - ) -> Optional[ModuleSpec]: - ... +class MetaPathFinder(Finder): + def find_module(self, fullname: str, + path: Optional[Sequence[_Path]]) -> Optional[Loader]: + ... + def invalidate_caches(self) -> None: ... + # Not defined on the actual class, but expected to exist. + def find_spec( + self, fullname: str, path: Optional[Sequence[_Path]], + target: Optional[types.ModuleType] = ... + ) -> Optional[ModuleSpec]: + ... - class PathEntryFinder(Finder): - def find_module(self, fullname: str) -> Optional[Loader]: ... - def find_loader( - self, fullname: str - ) -> Tuple[Optional[Loader], Sequence[_Path]]: ... - def invalidate_caches(self) -> None: ... - if sys.version_info >= (3, 4): - # Not defined on the actual class, but expected to exist. - def find_spec( - self, fullname: str, - target: Optional[types.ModuleType] = ... - ) -> Optional[ModuleSpec]: ... +class PathEntryFinder(Finder): + def find_module(self, fullname: str) -> Optional[Loader]: ... + def find_loader( + self, fullname: str + ) -> Tuple[Optional[Loader], Sequence[_Path]]: ... + def invalidate_caches(self) -> None: ... + # Not defined on the actual class, but expected to exist. + def find_spec( + self, fullname: str, + target: Optional[types.ModuleType] = ... + ) -> Optional[ModuleSpec]: ... - class FileLoader(ResourceLoader, ExecutionLoader, metaclass=ABCMeta): - name = ... # type: str - path = ... # type: _Path - def __init__(self, fullname: str, path: _Path) -> None: ... - def get_data(self, path: _Path) -> bytes: ... - def get_filename(self, fullname: str) -> _Path: ... +class FileLoader(ResourceLoader, ExecutionLoader, metaclass=ABCMeta): + name = ... # type: str + path = ... # type: _Path + def __init__(self, fullname: str, path: _Path) -> None: ... + def get_data(self, path: _Path) -> bytes: ... + def get_filename(self, fullname: str) -> _Path: ... if sys.version_info >= (3, 7): _PathLike = Union[bytes, str, os.PathLike[Any]] diff --git a/stdlib/3/importlib/machinery.pyi b/stdlib/3/importlib/machinery.pyi index d4ed8c376..98c4b9a5a 100644 --- a/stdlib/3/importlib/machinery.pyi +++ b/stdlib/3/importlib/machinery.pyi @@ -5,181 +5,116 @@ from typing import Any, Callable, List, Optional, Sequence, Tuple, Union # ModuleSpec is exported from this module, but for circular import # reasons exists in its own stub file (with Loader and ModuleType). -if sys.version_info >= (3, 4): - from _importlib_modulespec import ModuleSpec as ModuleSpec # Exported +from _importlib_modulespec import ModuleSpec as ModuleSpec # Exported -if sys.version_info >= (3, 3): - class BuiltinImporter(importlib.abc.MetaPathFinder, - importlib.abc.InspectLoader): - # MetaPathFinder - @classmethod - def find_module( - cls, fullname: str, - path: Optional[Sequence[importlib.abc._Path]] - ) -> Optional[importlib.abc.Loader]: +class BuiltinImporter(importlib.abc.MetaPathFinder, + importlib.abc.InspectLoader): + # MetaPathFinder + @classmethod + def find_module( + cls, fullname: str, + path: Optional[Sequence[importlib.abc._Path]] + ) -> Optional[importlib.abc.Loader]: + ... + @classmethod + def find_spec(cls, fullname: str, + path: Optional[Sequence[importlib.abc._Path]], + target: Optional[types.ModuleType] = ...) -> Optional[ModuleSpec]: ... - if sys.version_info >= (3, 4): - @classmethod - def find_spec(cls, fullname: str, - path: Optional[Sequence[importlib.abc._Path]], - target: Optional[types.ModuleType] = ...) -> Optional[ModuleSpec]: - ... - # InspectLoader - @classmethod - def is_package(cls, fullname: str) -> bool: ... - @classmethod - def load_module(cls, fullname: str) -> types.ModuleType: ... - @classmethod - def get_code(cls, fullname: str) -> None: ... - @classmethod - def get_source(cls, fullname: str) -> None: ... - # Loader - @classmethod - def load_module(cls, fullname: str) -> types.ModuleType: ... - if sys.version_info >= (3, 3): - @staticmethod - def module_repr(module: types.ModuleType) -> str: ... # type: ignore - if sys.version_info >= (3, 4): - @classmethod - def create_module(cls, spec: ModuleSpec) -> Optional[types.ModuleType]: ... - @classmethod - def exec_module(cls, module: types.ModuleType) -> None: ... -else: - class BuiltinImporter(importlib.abc.InspectLoader): - # MetaPathFinder - @classmethod - def find_module( - cls, fullname: str, - path: Optional[Sequence[importlib.abc._Path]] - ) -> Optional[importlib.abc.Loader]: - ... - # InspectLoader - @classmethod - def is_package(cls, fullname: str) -> bool: ... - @classmethod - def load_module(cls, fullname: str) -> types.ModuleType: ... - @classmethod - def get_code(cls, fullname: str) -> None: ... - @classmethod - def get_source(cls, fullname: str) -> None: ... - # Loader - @classmethod - def load_module(cls, fullname: str) -> types.ModuleType: ... + # InspectLoader + @classmethod + def is_package(cls, fullname: str) -> bool: ... + @classmethod + def load_module(cls, fullname: str) -> types.ModuleType: ... + @classmethod + def get_code(cls, fullname: str) -> None: ... + @classmethod + def get_source(cls, fullname: str) -> None: ... + # Loader + @classmethod + def load_module(cls, fullname: str) -> types.ModuleType: ... + @staticmethod + def module_repr(module: types.ModuleType) -> str: ... # type: ignore + @classmethod + def create_module(cls, spec: ModuleSpec) -> Optional[types.ModuleType]: ... + @classmethod + def exec_module(cls, module: types.ModuleType) -> None: ... -if sys.version_info >= (3, 3): - class FrozenImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader): - # MetaPathFinder - @classmethod - def find_module( - cls, fullname: str, - path: Optional[Sequence[importlib.abc._Path]] - ) -> Optional[importlib.abc.Loader]: - ... - if sys.version_info >= (3, 4): - @classmethod - def find_spec(cls, fullname: str, - path: Optional[Sequence[importlib.abc._Path]], - target: Optional[types.ModuleType] = ...) -> Optional[ModuleSpec]: - ... - # InspectLoader - @classmethod - def is_package(cls, fullname: str) -> bool: ... - @classmethod - def load_module(cls, fullname: str) -> types.ModuleType: ... - @classmethod - def get_code(cls, fullname: str) -> None: ... - @classmethod - def get_source(cls, fullname: str) -> None: ... - # Loader - @classmethod - def load_module(cls, fullname: str) -> types.ModuleType: ... - if sys.version_info >= (3, 3): - @staticmethod - def module_repr(module: types.ModuleType) -> str: ... # type: ignore - if sys.version_info >= (3, 4): - @classmethod - def create_module(cls, spec: ModuleSpec) -> Optional[types.ModuleType]: - ... - @staticmethod - def exec_module(module: types.ModuleType) -> None: ... # type: ignore -else: - class FrozenImporter(importlib.abc.InspectLoader): - # MetaPathFinder - @classmethod - def find_module( - cls, fullname: str, - path: Optional[Sequence[importlib.abc._Path]] - ) -> Optional[importlib.abc.Loader]: - ... - # InspectLoader - @classmethod - def is_package(cls, fullname: str) -> bool: ... - @classmethod - def load_module(cls, fullname: str) -> types.ModuleType: ... - @classmethod - def get_code(cls, fullname: str) -> None: ... # type: ignore - @classmethod - def get_source(cls, fullname: str) -> None: ... # type: ignore - # Loader - @classmethod - def load_module(cls, fullname: str) -> types.ModuleType: ... +class FrozenImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader): + # MetaPathFinder + @classmethod + def find_module( + cls, fullname: str, + path: Optional[Sequence[importlib.abc._Path]] + ) -> Optional[importlib.abc.Loader]: + ... + @classmethod + def find_spec(cls, fullname: str, + path: Optional[Sequence[importlib.abc._Path]], + target: Optional[types.ModuleType] = ...) -> Optional[ModuleSpec]: + ... + # InspectLoader + @classmethod + def is_package(cls, fullname: str) -> bool: ... + @classmethod + def load_module(cls, fullname: str) -> types.ModuleType: ... + @classmethod + def get_code(cls, fullname: str) -> None: ... + @classmethod + def get_source(cls, fullname: str) -> None: ... + # Loader + @classmethod + def load_module(cls, fullname: str) -> types.ModuleType: ... + @staticmethod + def module_repr(module: types.ModuleType) -> str: ... # type: ignore + @classmethod + def create_module(cls, spec: ModuleSpec) -> Optional[types.ModuleType]: + ... + @staticmethod + def exec_module(module: types.ModuleType) -> None: ... # type: ignore -if sys.version_info >= (3, 3): - class WindowsRegistryFinder(importlib.abc.MetaPathFinder): - @classmethod - def find_module( - cls, fullname: str, - path: Optional[Sequence[importlib.abc._Path]] - ) -> Optional[importlib.abc.Loader]: - ... - if sys.version_info >= (3, 4): - @classmethod - def find_spec(cls, fullname: str, - path: Optional[Sequence[importlib.abc._Path]], - target: Optional[types.ModuleType] = ...) -> Optional[ModuleSpec]: - ... -else: - class WindowsRegisteryFinder: - @classmethod - def find_module( - cls, fullname: str, - path: Optional[Sequence[importlib.abc._Path]] - ) -> Optional[importlib.abc.Loader]: - ... +class WindowsRegistryFinder(importlib.abc.MetaPathFinder): + @classmethod + def find_module( + cls, fullname: str, + path: Optional[Sequence[importlib.abc._Path]] + ) -> Optional[importlib.abc.Loader]: + ... + @classmethod + def find_spec(cls, fullname: str, + path: Optional[Sequence[importlib.abc._Path]], + target: Optional[types.ModuleType] = ...) -> Optional[ModuleSpec]: + ... -if sys.version_info >= (3, 3): - class PathFinder(importlib.abc.MetaPathFinder): ... -else: - class PathFinder: ... +class PathFinder(importlib.abc.MetaPathFinder): ... -if sys.version_info >= (3, 3): - SOURCE_SUFFIXES = ... # type: List[str] - DEBUG_BYTECODE_SUFFIXES = ... # type: List[str] - OPTIMIZED_BYTECODE_SUFFIXES = ... # type: List[str] - BYTECODE_SUFFIXES = ... # type: List[str] - EXTENSION_SUFFIXES = ... # type: List[str] +SOURCE_SUFFIXES = ... # type: List[str] +DEBUG_BYTECODE_SUFFIXES = ... # type: List[str] +OPTIMIZED_BYTECODE_SUFFIXES = ... # type: List[str] +BYTECODE_SUFFIXES = ... # type: List[str] +EXTENSION_SUFFIXES = ... # type: List[str] - def all_suffixes() -> List[str]: ... +def all_suffixes() -> List[str]: ... - class FileFinder(importlib.abc.PathEntryFinder): - path = ... # type: str - def __init__( - self, path: str, - *loader_details: Tuple[importlib.abc.Loader, List[str]] - ) -> None: ... - @classmethod - def path_hook( - *loader_details: Tuple[importlib.abc.Loader, List[str]] - ) -> Callable[[str], importlib.abc.PathEntryFinder]: ... +class FileFinder(importlib.abc.PathEntryFinder): + path = ... # type: str + def __init__( + self, path: str, + *loader_details: Tuple[importlib.abc.Loader, List[str]] + ) -> None: ... + @classmethod + def path_hook( + *loader_details: Tuple[importlib.abc.Loader, List[str]] + ) -> Callable[[str], importlib.abc.PathEntryFinder]: ... - class SourceFileLoader(importlib.abc.FileLoader, +class SourceFileLoader(importlib.abc.FileLoader, + importlib.abc.SourceLoader): + ... + +class SourcelessFileLoader(importlib.abc.FileLoader, importlib.abc.SourceLoader): - ... + ... - class SourcelessFileLoader(importlib.abc.FileLoader, - importlib.abc.SourceLoader): - ... - - class ExtensionFileLoader(importlib.abc.ExecutionLoader): - def get_filename(self, fullname: str) -> importlib.abc._Path: ... - def get_source(self, fullname: str) -> None: ... # type: ignore +class ExtensionFileLoader(importlib.abc.ExecutionLoader): + def get_filename(self, fullname: str) -> importlib.abc._Path: ... + def get_source(self, fullname: str) -> None: ... # type: ignore diff --git a/stdlib/3/importlib/util.pyi b/stdlib/3/importlib/util.pyi index d488630b9..801f93738 100644 --- a/stdlib/3/importlib/util.pyi +++ b/stdlib/3/importlib/util.pyi @@ -14,29 +14,27 @@ def set_package( fxn: Callable[..., types.ModuleType] ) -> Callable[..., types.ModuleType]: ... -if sys.version_info >= (3, 3): - def resolve_name(name: str, package: str) -> str: ... +def resolve_name(name: str, package: str) -> str: ... -if sys.version_info >= (3, 4): - MAGIC_NUMBER = ... # type: bytes +MAGIC_NUMBER = ... # type: bytes - def cache_from_source(path: str, debug_override: Optional[bool] = ..., *, - optimization: Optional[Any] = ...) -> str: ... - def source_from_cache(path: str) -> str: ... - def decode_source(source_bytes: bytes) -> str: ... - def find_spec( - name: str, package: Optional[str] = ... - ) -> Optional[importlib.machinery.ModuleSpec]: ... - def spec_from_loader( - name: str, loader: Optional[importlib.abc.Loader], *, - origin: Optional[str] = ..., loader_state: Optional[Any] = ..., - is_package: Optional[bool] = ... - ) -> importlib.machinery.ModuleSpec: ... - def spec_from_file_location( - name: str, location: str, *, - loader: Optional[importlib.abc.Loader] = ..., - submodule_search_locations: Optional[List[str]] = ... - ) -> importlib.machinery.ModuleSpec: ... +def cache_from_source(path: str, debug_override: Optional[bool] = ..., *, + optimization: Optional[Any] = ...) -> str: ... +def source_from_cache(path: str) -> str: ... +def decode_source(source_bytes: bytes) -> str: ... +def find_spec( + name: str, package: Optional[str] = ... +) -> Optional[importlib.machinery.ModuleSpec]: ... +def spec_from_loader( + name: str, loader: Optional[importlib.abc.Loader], *, + origin: Optional[str] = ..., loader_state: Optional[Any] = ..., + is_package: Optional[bool] = ... +) -> importlib.machinery.ModuleSpec: ... +def spec_from_file_location( + name: str, location: str, *, + loader: Optional[importlib.abc.Loader] = ..., + submodule_search_locations: Optional[List[str]] = ... +) -> importlib.machinery.ModuleSpec: ... if sys.version_info >= (3, 5): def module_from_spec(