diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index 29d91719c50c..18189db6213f 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -157,7 +157,6 @@ _ctypes.CFuncPtr # stubtest erroneously thinks it can't be subclassed _frozen_importlib_external.ExtensionFileLoader.get_filename _frozen_importlib_external.FileLoader.get_filename _frozen_importlib_external.FileLoader.get_resource_reader -_frozen_importlib_external.FileLoader.load_module # Mismatch of default values of `report` parameter: _markupbase.ParserBase.parse_comment @@ -277,7 +276,6 @@ importlib._abc.Loader.exec_module # See Lib/importlib/_abc.py. Might be defined # runtime is *args, **kwargs due to a wrapper; we have more accurate signatures in the stubs importlib.abc.FileLoader.get_filename -importlib.abc.FileLoader.load_module importlib.metadata._meta.SimplePath.joinpath # Runtime definition of protocol is incorrect diff --git a/stdlib/@tests/stubtest_allowlists/py310.txt b/stdlib/@tests/stubtest_allowlists/py310.txt index 4f1fe3bae1fd..2ff1c4c38385 100644 --- a/stdlib/@tests/stubtest_allowlists/py310.txt +++ b/stdlib/@tests/stubtest_allowlists/py310.txt @@ -162,6 +162,10 @@ typing(_extensions)?\.IO\.writelines posixpath.join ntpath.join +# runtime is *args, **kwargs due to a wrapper; we have more accurate signatures in the stubs +_frozen_importlib_external.FileLoader.load_module +importlib.abc.FileLoader.load_module + # =============================================================== # Allowlist entries that cannot or should not be fixed; 3.10 only diff --git a/stdlib/@tests/stubtest_allowlists/py311.txt b/stdlib/@tests/stubtest_allowlists/py311.txt index 69f314e576ab..f11779d324f1 100644 --- a/stdlib/@tests/stubtest_allowlists/py311.txt +++ b/stdlib/@tests/stubtest_allowlists/py311.txt @@ -140,6 +140,10 @@ typing(_extensions)?\.IO\.writelines posixpath.join ntpath.join +# runtime is *args, **kwargs due to a wrapper; we have more accurate signatures in the stubs +_frozen_importlib_external.FileLoader.load_module +importlib.abc.FileLoader.load_module + # ============================================================= # Allowlist entries that cannot or should not be fixed; >= 3.11 diff --git a/stdlib/@tests/stubtest_allowlists/py312.txt b/stdlib/@tests/stubtest_allowlists/py312.txt index 28f037fe9099..92c3ed2db44b 100644 --- a/stdlib/@tests/stubtest_allowlists/py312.txt +++ b/stdlib/@tests/stubtest_allowlists/py312.txt @@ -133,6 +133,10 @@ typing(_extensions)?\.IO\.writelines posixpath.join ntpath.join +# runtime is *args, **kwargs due to a wrapper; we have more accurate signatures in the stubs +_frozen_importlib_external.FileLoader.load_module +importlib.abc.FileLoader.load_module + # ============================================================= # Allowlist entries that cannot or should not be fixed; >= 3.12 diff --git a/stdlib/@tests/stubtest_allowlists/py313.txt b/stdlib/@tests/stubtest_allowlists/py313.txt index 22dcac6f46ca..4a8e9d615f99 100644 --- a/stdlib/@tests/stubtest_allowlists/py313.txt +++ b/stdlib/@tests/stubtest_allowlists/py313.txt @@ -91,6 +91,10 @@ typing(_extensions)?\.IO\.writelines posixpath.join ntpath.join +# runtime is *args, **kwargs due to a wrapper; we have more accurate signatures in the stubs +_frozen_importlib_external.FileLoader.load_module +importlib.abc.FileLoader.load_module + # ============================================================= # Allowlist entries that cannot or should not be fixed; >= 3.13 diff --git a/stdlib/@tests/stubtest_allowlists/py314.txt b/stdlib/@tests/stubtest_allowlists/py314.txt index caac7ec2a477..50e1a111832a 100644 --- a/stdlib/@tests/stubtest_allowlists/py314.txt +++ b/stdlib/@tests/stubtest_allowlists/py314.txt @@ -88,6 +88,10 @@ typing(_extensions)?\.IO\.writelines posixpath.join ntpath.join +# runtime is *args, **kwargs due to a wrapper; we have more accurate signatures in the stubs +_frozen_importlib_external.FileLoader.load_module +importlib.abc.FileLoader.load_module + # ============================================================= # Allowlist entries that cannot or should not be fixed; >= 3.14 diff --git a/stdlib/@tests/stubtest_allowlists/py315.txt b/stdlib/@tests/stubtest_allowlists/py315.txt index 5fe7d44569e9..b93738f041ec 100644 --- a/stdlib/@tests/stubtest_allowlists/py315.txt +++ b/stdlib/@tests/stubtest_allowlists/py315.txt @@ -2,21 +2,12 @@ # TODO: Allowlist entries that should be fixed # ============================================ -_frozen_importlib.BuiltinImporter.load_module -_frozen_importlib.FrozenImporter.load_module -_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 dataclasses.MISSING dataclasses._MISSING_TYPE dataclasses.field -importlib._abc.Loader.load_module -importlib._bootstrap_external.NamespacePath -importlib.resources._common.package_to_anchor mailbox._ProxyFile.__class_getitem__ # ============================================================= @@ -144,9 +135,6 @@ typing_extensions.Protocol # Super-special typing primitive # Allowlist entries that cannot or should not be fixed; >= 3.12 # ============================================================= -# Deprecated argument is supported at runtime by renaming it through a decorator. -importlib.resources._common.files - sys._monitoring # Doesn't really exist. See comments in the stub. sys.__jit # Similar to sys._monitoring sys.last_exc # Not always defined. diff --git a/stdlib/_frozen_importlib.pyi b/stdlib/_frozen_importlib.pyi index 172da4522d8f..7bb8d40a932a 100644 --- a/stdlib/_frozen_importlib.pyi +++ b/stdlib/_frozen_importlib.pyi @@ -16,6 +16,8 @@ def __import__( fromlist: Sequence[str] | None = (), level: int = 0, ) -> ModuleType: ... + +# TODO: Revise the protocol for 'loader' param def spec_from_loader( name: str, loader: LoaderProtocol | None, *, origin: str | None = None, is_package: bool | None = None ) -> importlib.machinery.ModuleSpec | None: ... @@ -61,11 +63,13 @@ class BuiltinImporter(importlib.abc.MetaPathFinder, importlib.abc.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: ... + if sys.version_info < (3, 15): + @classmethod + @deprecated("Deprecated since Python 3.10; removed in Python 3.15. Use `exec_module()` instead.") + def load_module(cls, fullname: str) -> types.ModuleType: ... # Loader if sys.version_info < (3, 12): @staticmethod @@ -95,11 +99,13 @@ class FrozenImporter(importlib.abc.MetaPathFinder, importlib.abc.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: ... + if sys.version_info < (3, 15): + @classmethod + @deprecated("Deprecated since Python 3.10; removed in Python 3.15. Use `exec_module()` instead.") + def load_module(cls, fullname: str) -> types.ModuleType: ... # Loader if sys.version_info < (3, 12): @staticmethod diff --git a/stdlib/_frozen_importlib_external.pyi b/stdlib/_frozen_importlib_external.pyi index 907e8def9380..210ec65a00af 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; 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: ... @@ -88,7 +92,9 @@ 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.10; 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: ... @@ -106,8 +112,10 @@ class FileLoader: def __init__(self, fullname: str, path: str) -> None: ... def get_data(self, path: str) -> bytes: ... def get_filename(self, fullname: str | None = None) -> str: ... - def load_module(self, fullname: str | None = None) -> types.ModuleType: ... def get_resource_reader(self, name: str | None = None) -> importlib.readers.FileReader: ... + 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 | None = None) -> types.ModuleType: ... 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: ... @@ -134,6 +142,18 @@ 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: ... + if sys.version_info >= (3, 11): class NamespaceLoader(importlib.abc.InspectLoader): def __init__( @@ -144,9 +164,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: ... def get_resource_reader(self, module: types.ModuleType) -> importlib.readers.NamespaceReader: ... + 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: ... if sys.version_info < (3, 12): @staticmethod @deprecated( @@ -166,7 +187,7 @@ else: 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.") + @deprecated("Deprecated since Python 3.10; removed in Python 3.15. Use `exec_module()` instead.") def load_module(self, fullname: str) -> types.ModuleType: ... @staticmethod @deprecated( diff --git a/stdlib/importlib/_abc.pyi b/stdlib/importlib/_abc.pyi index e8c80c0447ae..bf248ac1fda1 100644 --- a/stdlib/importlib/_abc.pyi +++ b/stdlib/importlib/_abc.pyi @@ -5,7 +5,9 @@ from importlib.machinery import ModuleSpec from typing_extensions import deprecated class Loader(metaclass=ABCMeta): - 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: ... if sys.version_info < (3, 12): @deprecated( "Deprecated since Python 3.4; removed in Python 3.12. " diff --git a/stdlib/importlib/abc.pyi b/stdlib/importlib/abc.pyi index ae4753f3e5bd..dffe99b86405 100644 --- a/stdlib/importlib/abc.pyi +++ b/stdlib/importlib/abc.pyi @@ -99,7 +99,9 @@ class FileLoader(_bootstrap_external.FileLoader, ResourceLoader, ExecutionLoader def __init__(self, fullname: str, path: str) -> None: ... def get_data(self, path: str) -> bytes: ... def get_filename(self, fullname: str | None = None) -> str: ... - def load_module(self, fullname: str | None = None) -> 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 | None = None) -> types.ModuleType: ... if sys.version_info < (3, 11): class ResourceReader(metaclass=ABCMeta): diff --git a/stdlib/importlib/resources/_common.pyi b/stdlib/importlib/resources/_common.pyi index 447cc1ea33b8..c0a96fa38fa4 100644 --- a/stdlib/importlib/resources/_common.pyi +++ b/stdlib/importlib/resources/_common.pyi @@ -12,9 +12,14 @@ if sys.version_info >= (3, 11): Package: TypeAlias = str | types.ModuleType - if sys.version_info >= (3, 12): + if sys.version_info >= (3, 15): + Anchor: TypeAlias = Package + + def files(anchor: Anchor | None = None) -> Traversable: ... + elif sys.version_info >= (3, 12): Anchor: TypeAlias = Package + @deprecated("Deprecated since Python 3.12; removed in Python 3.15.") def package_to_anchor( func: Callable[[Anchor | None], Traversable], ) -> Callable[[Anchor | None, Anchor | None], Traversable]: ... @@ -22,7 +27,7 @@ if sys.version_info >= (3, 11): @overload def files(anchor: Anchor | None = None) -> Traversable: ... @overload - @deprecated("Deprecated since Python 3.12; will be removed in Python 3.15. Use `anchor` parameter instead.") + @deprecated("Deprecated since Python 3.12; removed in Python 3.15. Use `anchor` parameter instead.") def files(package: Anchor | None = None) -> Traversable: ... else: