Add importlib.machinery.NamespaceLoader (#11074)

This commit is contained in:
Alex Waygood
2023-11-28 20:02:24 +00:00
committed by GitHub
parent 53592e421a
commit 9bbfa3362a
2 changed files with 25 additions and 2 deletions

View File

@@ -2,8 +2,9 @@ import importlib.abc
import sys
import types
from _typeshed import ReadableBuffer
from collections.abc import Callable, Iterable, Sequence
from collections.abc import Callable, Iterable, MutableSequence, Sequence
from typing import Any
from typing_extensions import Literal, deprecated
if sys.version_info >= (3, 8):
from importlib.metadata import DistributionFinder, PathDistribution
@@ -158,3 +159,23 @@ class ExtensionFileLoader(importlib.abc.ExecutionLoader):
def get_code(self, fullname: str) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __hash__(self) -> int: ...
if sys.version_info >= (3, 11):
import importlib.readers
class NamespaceLoader(importlib.abc.InspectLoader):
def __init__(
self, name: str, path: MutableSequence[str], path_finder: Callable[[str, tuple[str, ...]], ModuleSpec]
) -> None: ...
def is_package(self, fullname: str) -> Literal[True]: ...
def get_source(self, fullname: str) -> Literal[""]: ...
def get_code(self, fullname: str) -> types.CodeType: ...
def create_module(self, spec: ModuleSpec) -> None: ...
def exec_module(self, module: types.ModuleType) -> None: ...
@deprecated("load_module() is deprecated; use exec_module() instead")
def load_module(self, fullname: str) -> types.ModuleType: ...
def get_resource_reader(self, module: types.ModuleType) -> importlib.readers.NamespaceReader: ...
if sys.version_info < (3, 12):
@staticmethod
@deprecated("module_repr() is deprecated, and has been removed in Python 3.12")
def module_repr(module: types.ModuleType) -> str: ...

View File

@@ -26,7 +26,9 @@ __all__ = [
if sys.version_info >= (3, 8):
__all__ += ["Path"]
_DateTuple: TypeAlias = tuple[int, int, int, int, int, int]
# TODO: use TypeAlias when mypy bugs are fixed
# https://github.com/python/mypy/issues/16581
_DateTuple = tuple[int, int, int, int, int, int] # noqa: Y026
_ReadWriteMode: TypeAlias = Literal["r", "w"]
_ReadWriteBinaryMode: TypeAlias = Literal["r", "w", "rb", "wb"]
_ZipFileMode: TypeAlias = Literal["r", "w", "x", "a"]