diff --git a/stdlib/@tests/stubtest_allowlists/py315.txt b/stdlib/@tests/stubtest_allowlists/py315.txt index 7354dac4dc90..0099a1092eca 100644 --- a/stdlib/@tests/stubtest_allowlists/py315.txt +++ b/stdlib/@tests/stubtest_allowlists/py315.txt @@ -4,14 +4,6 @@ _frozen_importlib.BuiltinImporter.load_module _frozen_importlib.FrozenImporter.load_module -_frozen_importlib_external.FileFinder.discover -_frozen_importlib_external.NamespaceLoader.load_module -_frozen_importlib_external.NamespacePath -_frozen_importlib_external.PathFinder.discover -_frozen_importlib_external.SourceFileLoader.source_to_code -_frozen_importlib_external.SourceLoader.source_to_code -_frozen_importlib_external._LoaderBasics.load_module -_frozen_importlib_external.cache_from_source _struct.Struct.pack_into _struct.pack _struct.pack_into diff --git a/stdlib/_frozen_importlib_external.pyi b/stdlib/_frozen_importlib_external.pyi index 907e8def9380..d6138be5725a 100644 --- a/stdlib/_frozen_importlib_external.pyi +++ b/stdlib/_frozen_importlib_external.pyi @@ -6,7 +6,7 @@ import sys import types from _typeshed import ReadableBuffer, StrOrBytesPath, StrPath from _typeshed.importlib import LoaderProtocol -from collections.abc import Callable, Iterable, Mapping, MutableSequence, Sequence +from collections.abc import Callable, Iterable, Iterator, Mapping, MutableSequence, Sequence from importlib.machinery import ModuleSpec from importlib.metadata import DistributionFinder, PathDistribution from typing import Any, Final, Literal, overload @@ -23,13 +23,17 @@ else: MAGIC_NUMBER: Final[bytes] -@overload -@deprecated( - "The `debug_override` parameter is deprecated since Python 3.5; will be removed in Python 3.15. Use `optimization` instead." -) -def cache_from_source(path: StrPath, debug_override: bool, *, optimization: None = None) -> str: ... -@overload -def cache_from_source(path: StrPath, debug_override: None = None, *, optimization: Any | None = None) -> str: ... +if sys.version_info >= (3, 15): + def cache_from_source(path: StrPath, *, optimization: Any | None = None) -> str: ... + +else: + @overload + @deprecated( + "The `debug_override` parameter is deprecated since Python 3.5; will be removed in Python 3.15. Use `optimization` instead." + ) + def cache_from_source(path: StrPath, debug_override: bool, *, optimization: None = None) -> str: ... + @overload + def cache_from_source(path: StrPath, debug_override: None = None, *, optimization: Any | None = None) -> str: ... def source_from_cache(path: StrPath) -> str: ... def decode_source(source_bytes: ReadableBuffer) -> str: ... @@ -70,6 +74,10 @@ class PathFinder(importlib.abc.MetaPathFinder): @deprecated("Deprecated since Python 3.4; removed in Python 3.12. Use `find_spec()` instead.") def find_module(cls, fullname: str, path: Sequence[str] | None = None) -> importlib.abc.Loader | None: ... + if sys.version_info >= (3, 15): + @classmethod + def discover(cls, parent: ModuleSpec | None = None) -> Iterator[ModuleSpec]: ... + SOURCE_SUFFIXES: Final[list[str]] DEBUG_BYTECODE_SUFFIXES: Final = [".pyc"] OPTIMIZED_BYTECODE_SUFFIXES: Final = [".pyc"] @@ -83,21 +91,34 @@ class FileFinder(importlib.abc.PathEntryFinder): def path_hook( cls, *loader_details: tuple[type[importlib.abc.Loader], list[str]] ) -> Callable[[str], importlib.abc.PathEntryFinder]: ... + if sys.version_info >= (3, 15): + def discover(self, parent: ModuleSpec | None = None) -> Iterator[ModuleSpec]: ... class _LoaderBasics: def is_package(self, fullname: str) -> bool: ... def create_module(self, spec: ModuleSpec) -> types.ModuleType | None: ... def exec_module(self, module: types.ModuleType) -> None: ... - def load_module(self, fullname: str) -> types.ModuleType: ... + if sys.version_info < (3, 15): + @deprecated("Deprecated since Python 3.4; removed in Python 3.15. Use `exec_module()` instead.") + def load_module(self, fullname: str) -> types.ModuleType: ... class SourceLoader(_LoaderBasics): def path_mtime(self, path: str) -> float: ... def set_data(self, path: str, data: bytes) -> None: ... def get_source(self, fullname: str) -> str | None: ... def path_stats(self, path: str) -> Mapping[str, Any]: ... - def source_to_code( - self, data: ReadableBuffer | str | _ast.Module | _ast.Expression | _ast.Interactive, path: bytes | StrPath - ) -> types.CodeType: ... + if sys.version_info >= (3, 15): + def source_to_code( + self, + data: ReadableBuffer | str | _ast.Module | _ast.Expression | _ast.Interactive, + path: bytes | StrPath, + fullname: str | None = None, + ) -> types.CodeType: ... + else: + def source_to_code( + self, data: ReadableBuffer | str | _ast.Module | _ast.Expression | _ast.Interactive, path: bytes | StrPath + ) -> types.CodeType: ... + def get_code(self, fullname: str) -> types.CodeType | None: ... class FileLoader: @@ -112,13 +133,23 @@ class FileLoader: class SourceFileLoader(importlib.abc.FileLoader, FileLoader, importlib.abc.SourceLoader, SourceLoader): # type: ignore[misc] # incompatible method arguments in base classes def set_data(self, path: str, data: ReadableBuffer, *, _mode: int = 0o666) -> None: ... def path_stats(self, path: str) -> Mapping[str, Any]: ... - def source_to_code( # type: ignore[override] # incompatible with InspectLoader.source_to_code - self, - data: ReadableBuffer | str | _ast.Module | _ast.Expression | _ast.Interactive, - path: bytes | StrPath, - *, - _optimize: int = -1, - ) -> types.CodeType: ... + if sys.version_info >= (3, 15): + def source_to_code( # type: ignore[override] # incompatible with InspectLoader.source_to_code + self, + data: ReadableBuffer | str | _ast.Module | _ast.Expression | _ast.Interactive, + path: bytes | StrPath, + fullname: str | None = None, + *, + _optimize: int = -1, + ) -> types.CodeType: ... + else: + def source_to_code( # type: ignore[override] # incompatible with InspectLoader.source_to_code + self, + data: ReadableBuffer | str | _ast.Module | _ast.Expression | _ast.Interactive, + path: bytes | StrPath, + *, + _optimize: int = -1, + ) -> types.CodeType: ... class SourcelessFileLoader(importlib.abc.FileLoader, FileLoader, _LoaderBasics): def get_code(self, fullname: str) -> types.CodeType | None: ... @@ -134,6 +165,20 @@ class ExtensionFileLoader(FileLoader, _LoaderBasics, importlib.abc.ExecutionLoad def __eq__(self, other: object) -> bool: ... def __hash__(self) -> int: ... +if sys.version_info >= (3, 15): + class NamespacePath: + def __init__( + self, name: str, path: MutableSequence[str], path_finder: Callable[[str, tuple[str, ...]], ModuleSpec] + ) -> None: ... + def __iter__(self) -> Iterator[str]: ... + def __getitem__(self, index: int) -> str: ... + def __setitem__(self, index: int, path: str) -> None: ... + def __len__(self) -> int: ... + def __contains__(self, item: str) -> bool: ... + def append(self, item: str) -> None: ... + + _NamespacePath = NamespacePath + if sys.version_info >= (3, 11): class NamespaceLoader(importlib.abc.InspectLoader): def __init__( @@ -144,8 +189,10 @@ if sys.version_info >= (3, 11): def get_code(self, fullname: str) -> types.CodeType: ... def create_module(self, spec: ModuleSpec) -> None: ... def exec_module(self, module: types.ModuleType) -> None: ... - @deprecated("Deprecated since Python 3.10; will be removed in Python 3.15. Use `exec_module()` instead.") - def load_module(self, fullname: str) -> types.ModuleType: ... + if sys.version_info < (3, 15): + @deprecated("Deprecated since Python 3.10; removed in Python 3.15. 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