From fd558f8acf0ecdeecf05da30ca7c67e31f6f7cad Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Mon, 11 Dec 2023 05:48:58 -0800 Subject: [PATCH] importlib.abc.Loader moved to importlib._abc.Loader in 3.10 (#11142) --- stdlib/VERSIONS | 1 + stdlib/importlib/_abc.pyi | 15 +++++++++++++++ stdlib/importlib/abc.pyi | 21 +++++++++++---------- tests/stubtest_allowlists/py310.txt | 1 + tests/stubtest_allowlists/py311.txt | 1 + tests/stubtest_allowlists/py312.txt | 1 + 6 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 stdlib/importlib/_abc.pyi diff --git a/stdlib/VERSIONS b/stdlib/VERSIONS index d24e85c8f..f5e30c460 100644 --- a/stdlib/VERSIONS +++ b/stdlib/VERSIONS @@ -150,6 +150,7 @@ imaplib: 2.7- imghdr: 2.7- imp: 2.7-3.11 importlib: 2.7- +importlib._abc: 3.10- importlib.metadata: 3.8- importlib.metadata._meta: 3.10- importlib.readers: 3.10- diff --git a/stdlib/importlib/_abc.pyi b/stdlib/importlib/_abc.pyi new file mode 100644 index 000000000..1a21b9a72 --- /dev/null +++ b/stdlib/importlib/_abc.pyi @@ -0,0 +1,15 @@ +import sys +import types +from abc import ABCMeta +from importlib.machinery import ModuleSpec + +if sys.version_info >= (3, 10): + class Loader(metaclass=ABCMeta): + def load_module(self, fullname: str) -> types.ModuleType: ... + if sys.version_info < (3, 12): + def module_repr(self, module: types.ModuleType) -> str: ... + + 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: ... diff --git a/stdlib/importlib/abc.pyi b/stdlib/importlib/abc.pyi index a7c69dc13..eb13240f8 100644 --- a/stdlib/importlib/abc.pyi +++ b/stdlib/importlib/abc.pyi @@ -24,19 +24,20 @@ if sys.version_info >= (3, 11): if sys.version_info < (3, 12): __all__ += ["Finder", "ResourceReader", "Traversable", "TraversableResources"] +if sys.version_info >= (3, 10): + from importlib._abc import Loader as Loader +else: + 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) -> 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: ... + if sys.version_info < (3, 12): class Finder(metaclass=ABCMeta): ... -class Loader(metaclass=ABCMeta): - def load_module(self, fullname: str) -> types.ModuleType: ... - if sys.version_info < (3, 12): - def module_repr(self, module: types.ModuleType) -> str: ... - - 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: ... - class ResourceLoader(Loader): @abstractmethod def get_data(self, path: str) -> bytes: ... diff --git a/tests/stubtest_allowlists/py310.txt b/tests/stubtest_allowlists/py310.txt index 9f93be81a..df8d27d8b 100644 --- a/tests/stubtest_allowlists/py310.txt +++ b/tests/stubtest_allowlists/py310.txt @@ -11,6 +11,7 @@ enum.Enum._generate_next_value_ functools._lru_cache_wrapper.cache_parameters # Cannot be detected statically gettext.install gettext.translation +importlib._abc.Loader.exec_module # See Lib/importlib/_abc.py. Might be defined for backwards compatibility importlib.abc.Finder.find_module importlib.metadata._meta.SimplePath.__truediv__ # See comments in the stub # platform.uname_result's processor field is now dynamically made to exist diff --git a/tests/stubtest_allowlists/py311.txt b/tests/stubtest_allowlists/py311.txt index 069a783f5..509e68adf 100644 --- a/tests/stubtest_allowlists/py311.txt +++ b/tests/stubtest_allowlists/py311.txt @@ -12,6 +12,7 @@ enum.Enum.__init__ enum.Enum._generate_next_value_ # Not strictly speaking a staticmethod on 3.11, but it acts like one: enum.StrEnum._generate_next_value_ +importlib._abc.Loader.exec_module # See Lib/importlib/_abc.py. Might be defined for backwards compatibility importlib.abc.Finder.find_module tkinter._VersionInfoType.__doc__ typing.NewType.__mro_entries__ diff --git a/tests/stubtest_allowlists/py312.txt b/tests/stubtest_allowlists/py312.txt index 7d358dce5..8847ee424 100644 --- a/tests/stubtest_allowlists/py312.txt +++ b/tests/stubtest_allowlists/py312.txt @@ -11,6 +11,7 @@ _csv.Reader _csv.Writer configparser.LegacyInterpolation.__init__ enum.Enum.__init__ +importlib._abc.Loader.exec_module # See Lib/importlib/_abc.py. Might be defined for backwards compatibility tkinter._VersionInfoType.__doc__ typing.NewType.__mro_entries__