Update importlib to reflect recent changes (#6557)

This commit is contained in:
Alex Waygood
2021-12-10 13:32:55 +00:00
committed by GitHub
parent e330a74dc3
commit 84fd495b65
12 changed files with 65 additions and 24 deletions

View File

@@ -12,7 +12,7 @@ from _typeshed import (
from abc import ABCMeta, abstractmethod
from importlib.machinery import ModuleSpec
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper
from typing import IO, Any, BinaryIO, Iterator, Mapping, Protocol, Sequence, Union, overload
from typing import IO, Any, BinaryIO, Iterator, Mapping, NoReturn, Protocol, Sequence, Union, overload
from typing_extensions import Literal, runtime_checkable
_Path = Union[bytes, str]
@@ -173,3 +173,10 @@ if sys.version_info >= (3, 9):
def read_bytes(self) -> bytes: ...
@abstractmethod
def read_text(self, encoding: str | None = ...) -> str: ...
class TraversableResources(ResourceReader):
@abstractmethod
def files(self) -> Traversable: ...
def open_resource(self, resource: StrPath) -> BufferedReader: ... # type: ignore[override]
def resource_path(self, resource: Any) -> NoReturn: ...
def is_resource(self, path: StrPath) -> bool: ...
def contents(self) -> Iterator[str]: ...

View File

@@ -1,7 +1,10 @@
import importlib.abc
import sys
import types
from typing import Any, Callable, Sequence
from typing import Any, Callable, Iterable, Sequence
if sys.version_info >= (3, 8):
from importlib.metadata import DistributionFinder, PathDistribution
class ModuleSpec:
def __init__(
@@ -97,6 +100,12 @@ class PathFinder:
else:
@classmethod
def invalidate_caches(cls) -> None: ...
if sys.version_info >= (3, 10):
@staticmethod
def find_distributions(context: DistributionFinder.Context = ...) -> Iterable[PathDistribution]: ...
elif sys.version_info >= (3, 8):
@classmethod
def find_distributions(cls, context: DistributionFinder.Context = ...) -> Iterable[PathDistribution]: ...
@classmethod
def find_spec(
cls, fullname: str, path: Sequence[bytes | str] | None = ..., target: types.ModuleType | None = ...

View File

@@ -7,9 +7,10 @@ from email.message import Message
from importlib.abc import MetaPathFinder
from os import PathLike
from pathlib import Path
from typing import Any, Iterable, NamedTuple, Tuple, overload
from typing import Any, ClassVar, Iterable, NamedTuple, Pattern, Tuple, overload
if sys.version_info >= (3, 10):
from importlib.metadata._meta import PackageMetadata as PackageMetadata
def packages_distributions() -> Mapping[str, list[str]]: ...
if sys.version_info >= (3, 8):
@@ -19,9 +20,18 @@ if sys.version_info >= (3, 8):
value: str
group: str
class EntryPoint(_EntryPointBase):
pattern: ClassVar[Pattern[str]]
def load(self) -> Any: ... # Callable[[], Any] or an importable module
@property
def extras(self) -> list[str]: ...
if sys.version_info >= (3, 9):
@property
def module(self) -> str: ...
@property
def attr(self) -> str: ...
if sys.version_info >= (3, 10):
dist: ClassVar[Distribution | None]
def matches(self, **params: Any) -> bool: ... # undocumented
class PackagePath(pathlib.PurePosixPath):
def read_text(self, encoding: str = ...) -> str: ...
def read_binary(self) -> bytes: ...
@@ -61,6 +71,9 @@ if sys.version_info >= (3, 8):
def files(self) -> list[PackagePath] | None: ...
@property
def requires(self) -> list[str] | None: ...
if sys.version_info >= (3, 10):
@property
def name(self) -> str: ...
class DistributionFinder(MetaPathFinder):
class Context:
name: str | None

View File

@@ -0,0 +1,18 @@
from typing import Any, Iterator, Protocol, TypeVar
_T = TypeVar("_T")
class PackageMetadata(Protocol):
def __len__(self) -> int: ...
def __contains__(self, item: str) -> bool: ...
def __getitem__(self, key: str) -> str: ...
def __iter__(self) -> Iterator[str]: ...
def get_all(self, name: str, failobj: _T = ...) -> list[Any] | _T: ...
@property
def json(self) -> dict[str, str | list[str]]: ...
class SimplePath(Protocol):
def joinpath(self) -> SimplePath: ...
def __div__(self) -> SimplePath: ...
def parent(self) -> SimplePath: ...
def read_text(self) -> str: ...

View File

@@ -23,3 +23,6 @@ if sys.version_info >= (3, 9):
from importlib.abc import Traversable
def files(package: Package) -> Traversable: ...
def as_file(path: Traversable) -> AbstractContextManager[Path]: ...
if sys.version_info >= (3, 10):
from importlib.abc import ResourceReader as ResourceReader

View File

@@ -1,5 +1,6 @@
import importlib.abc
import importlib.machinery
import sys
import types
from _typeshed import StrOrBytesPath
from typing import Any, Callable
@@ -36,3 +37,6 @@ class LazyLoader(importlib.abc.Loader):
def factory(cls, loader: importlib.abc.Loader) -> Callable[..., LazyLoader]: ...
def create_module(self, spec: importlib.machinery.ModuleSpec) -> types.ModuleType | None: ...
def exec_module(self, module: types.ModuleType) -> None: ...
if sys.version_info >= (3, 7):
def source_hash(source_bytes: bytes) -> int: ...