Big diff: Use new "|" union syntax (#5872)

This commit is contained in:
Akuli
2021-08-08 12:05:21 +03:00
committed by GitHub
parent b9adb7a874
commit ee487304d7
578 changed files with 8080 additions and 8966 deletions

View File

@@ -1,15 +1,15 @@
import types
from importlib.abc import Loader
from typing import Any, Mapping, Optional, Sequence
from typing import Any, Mapping, Sequence
def __import__(
name: str,
globals: Optional[Mapping[str, Any]] = ...,
locals: Optional[Mapping[str, Any]] = ...,
globals: Mapping[str, Any] | None = ...,
locals: Mapping[str, Any] | None = ...,
fromlist: Sequence[str] = ...,
level: int = ...,
) -> types.ModuleType: ...
def import_module(name: str, package: Optional[str] = ...) -> types.ModuleType: ...
def find_loader(name: str, path: Optional[str] = ...) -> Optional[Loader]: ...
def import_module(name: str, package: str | None = ...) -> types.ModuleType: ...
def find_loader(name: str, path: str | None = ...) -> Loader | None: ...
def invalidate_caches() -> None: ...
def reload(module: types.ModuleType) -> types.ModuleType: ...

View File

@@ -3,7 +3,7 @@ import types
from _typeshed import StrOrBytesPath
from abc import ABCMeta, abstractmethod
from importlib.machinery import ModuleSpec
from typing import IO, Any, Iterator, Mapping, Optional, Protocol, Sequence, Tuple, Union
from typing import IO, Any, Iterator, Mapping, Protocol, Sequence, Tuple, Union
from typing_extensions import Literal, runtime_checkable
_Path = Union[bytes, str]
@@ -16,45 +16,45 @@ class ResourceLoader(Loader):
class InspectLoader(Loader):
def is_package(self, fullname: str) -> bool: ...
def get_code(self, fullname: str) -> Optional[types.CodeType]: ...
def get_code(self, fullname: str) -> types.CodeType | None: ...
def load_module(self, fullname: str) -> types.ModuleType: ...
@abstractmethod
def get_source(self, fullname: str) -> Optional[str]: ...
def get_source(self, fullname: str) -> str | None: ...
def exec_module(self, module: types.ModuleType) -> None: ...
@staticmethod
def source_to_code(data: Union[bytes, str], path: str = ...) -> types.CodeType: ...
def source_to_code(data: bytes | str, path: str = ...) -> types.CodeType: ...
class ExecutionLoader(InspectLoader):
@abstractmethod
def get_filename(self, fullname: str) -> _Path: ...
def get_code(self, fullname: str) -> Optional[types.CodeType]: ...
def get_code(self, fullname: str) -> types.CodeType | None: ...
class SourceLoader(ResourceLoader, ExecutionLoader, metaclass=ABCMeta):
def path_mtime(self, path: _Path) -> float: ...
def set_data(self, path: _Path, data: bytes) -> None: ...
def get_source(self, fullname: str) -> Optional[str]: ...
def get_source(self, fullname: str) -> str | None: ...
def path_stats(self, path: _Path) -> Mapping[str, Any]: ...
# Please keep in sync with sys._MetaPathFinder
class MetaPathFinder(Finder):
def find_module(self, fullname: str, path: Optional[Sequence[_Path]]) -> Optional[Loader]: ...
def find_module(self, fullname: str, path: Sequence[_Path] | None) -> Loader | None: ...
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]: ...
self, fullname: str, path: Sequence[_Path] | None, target: types.ModuleType | None = ...
) -> ModuleSpec | None: ...
class PathEntryFinder(Finder):
def find_module(self, fullname: str) -> Optional[Loader]: ...
def find_loader(self, fullname: str) -> Tuple[Optional[Loader], Sequence[_Path]]: ...
def find_module(self, fullname: str) -> Loader | None: ...
def find_loader(self, fullname: str) -> Tuple[Loader | None, 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]: ...
def find_spec(self, fullname: str, target: types.ModuleType | None = ...) -> ModuleSpec | None: ...
class Loader(metaclass=ABCMeta):
def load_module(self, fullname: str) -> types.ModuleType: ...
def module_repr(self, module: types.ModuleType) -> str: ...
def create_module(self, spec: ModuleSpec) -> Optional[types.ModuleType]: ...
def create_module(self, spec: ModuleSpec) -> types.ModuleType | None: ...
# Not defined on the actual class for backwards-compatibility reasons,
# but expected in new code.
def exec_module(self, module: types.ModuleType) -> None: ...
@@ -67,8 +67,8 @@ class FileLoader(ResourceLoader, ExecutionLoader, metaclass=ABCMeta):
path: _Path
def __init__(self, fullname: str, path: _Path) -> None: ...
def get_data(self, path: _Path) -> bytes: ...
def get_filename(self, name: Optional[str] = ...) -> _Path: ...
def load_module(self, name: Optional[str] = ...) -> types.ModuleType: ...
def get_filename(self, name: str | None = ...) -> _Path: ...
def load_module(self, name: str | None = ...) -> types.ModuleType: ...
if sys.version_info >= (3, 7):
class ResourceReader(metaclass=ABCMeta):
@@ -89,7 +89,7 @@ if sys.version_info >= (3, 9):
@abstractmethod
def read_bytes(self) -> bytes: ...
@abstractmethod
def read_text(self, encoding: Optional[str] = ...) -> str: ...
def read_text(self, encoding: str | None = ...) -> str: ...
@abstractmethod
def is_dir(self) -> bool: ...
@abstractmethod

View File

@@ -1,37 +1,35 @@
import importlib.abc
import types
from typing import Any, Callable, List, Optional, Sequence, Tuple, Union
from typing import Any, Callable, List, Sequence, Tuple
# TODO: the loaders seem a bit backwards, attribute is protocol but __init__ arg isn't?
class ModuleSpec:
def __init__(
self,
name: str,
loader: Optional[importlib.abc.Loader],
loader: importlib.abc.Loader | None,
*,
origin: Optional[str] = ...,
origin: str | None = ...,
loader_state: Any = ...,
is_package: Optional[bool] = ...,
is_package: bool | None = ...,
) -> None: ...
name: str
loader: Optional[importlib.abc._LoaderProtocol]
origin: Optional[str]
submodule_search_locations: Optional[List[str]]
loader: importlib.abc._LoaderProtocol | None
origin: str | None
submodule_search_locations: List[str] | None
loader_state: Any
cached: Optional[str]
parent: Optional[str]
cached: str | None
parent: str | None
has_location: bool
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]: ...
def find_module(cls, fullname: str, path: Sequence[importlib.abc._Path] | None = ...) -> importlib.abc.Loader | None: ...
@classmethod
def find_spec(
cls, fullname: str, path: Optional[Sequence[importlib.abc._Path]] = ..., target: Optional[types.ModuleType] = ...
) -> Optional[ModuleSpec]: ...
cls, fullname: str, path: Sequence[importlib.abc._Path] | None = ..., target: types.ModuleType | None = ...
) -> ModuleSpec | None: ...
# InspectLoader
@classmethod
def is_package(cls, fullname: str) -> bool: ...
@@ -45,20 +43,18 @@ class BuiltinImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader)
@staticmethod
def module_repr(module: types.ModuleType) -> str: ...
@classmethod
def create_module(cls, spec: ModuleSpec) -> Optional[types.ModuleType]: ...
def create_module(cls, spec: ModuleSpec) -> types.ModuleType | None: ...
@classmethod
def exec_module(cls, module: types.ModuleType) -> None: ...
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]: ...
def find_module(cls, fullname: str, path: Sequence[importlib.abc._Path] | None = ...) -> importlib.abc.Loader | None: ...
@classmethod
def find_spec(
cls, fullname: str, path: Optional[Sequence[importlib.abc._Path]] = ..., target: Optional[types.ModuleType] = ...
) -> Optional[ModuleSpec]: ...
cls, fullname: str, path: Sequence[importlib.abc._Path] | None = ..., target: types.ModuleType | None = ...
) -> ModuleSpec | None: ...
# InspectLoader
@classmethod
def is_package(cls, fullname: str) -> bool: ...
@@ -72,29 +68,27 @@ class FrozenImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader):
@staticmethod
def module_repr(m: types.ModuleType) -> str: ...
@classmethod
def create_module(cls, spec: ModuleSpec) -> Optional[types.ModuleType]: ...
def create_module(cls, spec: ModuleSpec) -> types.ModuleType | None: ...
@staticmethod
def exec_module(module: types.ModuleType) -> None: ...
class WindowsRegistryFinder(importlib.abc.MetaPathFinder):
@classmethod
def find_module(
cls, fullname: str, path: Optional[Sequence[importlib.abc._Path]] = ...
) -> Optional[importlib.abc.Loader]: ...
def find_module(cls, fullname: str, path: Sequence[importlib.abc._Path] | None = ...) -> importlib.abc.Loader | None: ...
@classmethod
def find_spec(
cls, fullname: str, path: Optional[Sequence[importlib.abc._Path]] = ..., target: Optional[types.ModuleType] = ...
) -> Optional[ModuleSpec]: ...
cls, fullname: str, path: Sequence[importlib.abc._Path] | None = ..., target: types.ModuleType | None = ...
) -> ModuleSpec | None: ...
class PathFinder:
@classmethod
def invalidate_caches(cls) -> None: ...
@classmethod
def find_spec(
cls, fullname: str, path: Optional[Sequence[Union[bytes, str]]] = ..., target: Optional[types.ModuleType] = ...
) -> Optional[ModuleSpec]: ...
cls, fullname: str, path: Sequence[bytes | str] | None = ..., target: types.ModuleType | None = ...
) -> ModuleSpec | None: ...
@classmethod
def find_module(cls, fullname: str, path: Optional[Sequence[Union[bytes, str]]] = ...) -> Optional[importlib.abc.Loader]: ...
def find_module(cls, fullname: str, path: Sequence[bytes | str] | None = ...) -> importlib.abc.Loader | None: ...
SOURCE_SUFFIXES: List[str]
DEBUG_BYTECODE_SUFFIXES: List[str]
@@ -119,5 +113,5 @@ class SourcelessFileLoader(importlib.abc.FileLoader, importlib.abc.SourceLoader)
class ExtensionFileLoader(importlib.abc.ExecutionLoader):
def __init__(self, name: str, path: importlib.abc._Path) -> None: ...
def get_filename(self, name: Optional[str] = ...) -> importlib.abc._Path: ...
def get_filename(self, name: str | None = ...) -> importlib.abc._Path: ...
def get_source(self, fullname: str) -> None: ...

View File

@@ -7,7 +7,7 @@ from email.message import Message
from importlib.abc import MetaPathFinder
from os import PathLike
from pathlib import Path
from typing import Any, Dict, Iterable, List, NamedTuple, Optional, Tuple, overload
from typing import Any, Dict, Iterable, List, NamedTuple, Tuple, overload
if sys.version_info >= (3, 10):
def packages_distributions() -> Mapping[str, List[str]]: ...
@@ -27,8 +27,8 @@ if sys.version_info >= (3, 8):
def read_binary(self) -> bytes: ...
def locate(self) -> PathLike[str]: ...
# The following attributes are not defined on PackagePath, but are dynamically added by Distribution.files:
hash: Optional[FileHash]
size: Optional[int]
hash: FileHash | None
size: int | None
dist: Distribution
class FileHash:
mode: str
@@ -36,7 +36,7 @@ if sys.version_info >= (3, 8):
def __init__(self, spec: str) -> None: ...
class Distribution:
@abc.abstractmethod
def read_text(self, filename: str) -> Optional[str]: ...
def read_text(self, filename: str) -> str | None: ...
@abc.abstractmethod
def locate_file(self, path: StrPath) -> PathLike[str]: ...
@classmethod
@@ -47,7 +47,7 @@ if sys.version_info >= (3, 8):
@overload
@classmethod
def discover(
cls, *, context: None = ..., name: Optional[str] = ..., path: List[str] = ..., **kwargs: Any
cls, *, context: None = ..., name: str | None = ..., path: List[str] = ..., **kwargs: Any
) -> Iterable[Distribution]: ...
@staticmethod
def at(path: StrPath) -> PathDistribution: ...
@@ -58,13 +58,13 @@ if sys.version_info >= (3, 8):
@property
def entry_points(self) -> List[EntryPoint]: ...
@property
def files(self) -> Optional[List[PackagePath]]: ...
def files(self) -> List[PackagePath] | None: ...
@property
def requires(self) -> Optional[List[str]]: ...
def requires(self) -> List[str] | None: ...
class DistributionFinder(MetaPathFinder):
class Context:
name: Optional[str]
def __init__(self, *, name: Optional[str] = ..., path: List[str] = ..., **kwargs: Any) -> None: ...
name: str | None
def __init__(self, *, name: str | None = ..., path: List[str] = ..., **kwargs: Any) -> None: ...
@property
def path(self) -> List[str]: ...
@abc.abstractmethod
@@ -81,10 +81,10 @@ if sys.version_info >= (3, 8):
def distributions(*, context: DistributionFinder.Context) -> Iterable[Distribution]: ...
@overload
def distributions(
*, context: None = ..., name: Optional[str] = ..., path: List[str] = ..., **kwargs: Any
*, context: None = ..., name: str | None = ..., path: List[str] = ..., **kwargs: Any
) -> Iterable[Distribution]: ...
def metadata(distribution_name: str) -> Message: ...
def version(distribution_name: str) -> str: ...
def entry_points() -> Dict[str, Tuple[EntryPoint, ...]]: ...
def files(distribution_name: str) -> Optional[List[PackagePath]]: ...
def requires(distribution_name: str) -> Optional[List[str]]: ...
def files(distribution_name: str) -> List[PackagePath] | None: ...
def requires(distribution_name: str) -> List[str] | None: ...

View File

@@ -2,7 +2,7 @@ import importlib.abc
import importlib.machinery
import types
from _typeshed import StrOrBytesPath
from typing import Any, Callable, List, Optional
from typing import Any, Callable, List
def module_for_loader(fxn: Callable[..., types.ModuleType]) -> Callable[..., types.ModuleType]: ...
def set_loader(fxn: Callable[..., types.ModuleType]) -> Callable[..., types.ModuleType]: ...
@@ -11,25 +11,25 @@ def resolve_name(name: str, package: str | None) -> str: ...
MAGIC_NUMBER: bytes
def cache_from_source(path: str, debug_override: Optional[bool] = ..., *, optimization: Optional[Any] = ...) -> str: ...
def cache_from_source(path: str, debug_override: bool | None = ..., *, optimization: Any | None = ...) -> 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 find_spec(name: str, package: str | None = ...) -> importlib.machinery.ModuleSpec | None: ...
def spec_from_loader(
name: str, loader: Optional[importlib.abc.Loader], *, origin: Optional[str] = ..., is_package: Optional[bool] = ...
) -> Optional[importlib.machinery.ModuleSpec]: ...
name: str, loader: importlib.abc.Loader | None, *, origin: str | None = ..., is_package: bool | None = ...
) -> importlib.machinery.ModuleSpec | None: ...
def spec_from_file_location(
name: str,
location: Optional[StrOrBytesPath] = ...,
location: StrOrBytesPath | None = ...,
*,
loader: Optional[importlib.abc.Loader] = ...,
submodule_search_locations: Optional[List[str]] = ...,
) -> Optional[importlib.machinery.ModuleSpec]: ...
loader: importlib.abc.Loader | None = ...,
submodule_search_locations: List[str] | None = ...,
) -> importlib.machinery.ModuleSpec | None: ...
def module_from_spec(spec: importlib.machinery.ModuleSpec) -> types.ModuleType: ...
class LazyLoader(importlib.abc.Loader):
def __init__(self, loader: importlib.abc.Loader) -> None: ...
@classmethod
def factory(cls, loader: importlib.abc.Loader) -> Callable[..., LazyLoader]: ...
def create_module(self, spec: importlib.machinery.ModuleSpec) -> Optional[types.ModuleType]: ...
def create_module(self, spec: importlib.machinery.ModuleSpec) -> types.ModuleType | None: ...
def exec_module(self, module: types.ModuleType) -> None: ...