From 5e7fb9c749a06f4888aa9489ced4acb323c5a055 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 17 Jun 2022 15:59:21 -0400 Subject: [PATCH] gh-93963: Officially deprecate abcs and warn about their usage. --- Lib/importlib/abc.py | 26 +++++++++++++++---- ...2-06-17-16-00-55.gh-issue-93963.8YYZ-2.rst | 2 ++ 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2022-06-17-16-00-55.gh-issue-93963.8YYZ-2.rst diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py index 3fa151f390ba7c..6bcc47f8271433 100644 --- a/Lib/importlib/abc.py +++ b/Lib/importlib/abc.py @@ -15,20 +15,36 @@ import abc import warnings -# for compatibility with Python 3.10 -from .resources.abc import ResourceReader, Traversable, TraversableResources +from .resources import abc as _resources_abc __all__ = [ 'Loader', 'Finder', 'MetaPathFinder', 'PathEntryFinder', 'ResourceLoader', 'InspectLoader', 'ExecutionLoader', 'FileLoader', 'SourceLoader', - - # for compatibility with Python 3.10 - 'ResourceReader', 'Traversable', 'TraversableResources', ] +def __getattr__(name, canonical=_resources_abc): + """ + For backwards compatibility, continue to make names + from canonical available through this module. + """ + if name in canonical.__all__: + obj = getattr(canonical, name) + import warnings + warnings.warn( + f"Using or importing the ABCs from {__name__!r} instead " + f"of from {canonical.__name__!r} is deprecated since " + "Python 3.11, and in 3.13 it will stop working", + DeprecationWarning, + stacklevel=2, + ) + globals()[name] = obj + return obj + raise AttributeError(f'module {__name__!r} has no attribute {name!r}') + + def _register(abstract_cls, *classes): for cls in classes: abstract_cls.register(cls) diff --git a/Misc/NEWS.d/next/Library/2022-06-17-16-00-55.gh-issue-93963.8YYZ-2.rst b/Misc/NEWS.d/next/Library/2022-06-17-16-00-55.gh-issue-93963.8YYZ-2.rst new file mode 100644 index 00000000000000..0973982dfeeffd --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-06-17-16-00-55.gh-issue-93963.8YYZ-2.rst @@ -0,0 +1,2 @@ +Officially deprecate from ``importlib.abc`` classes moved to +``importlib.resources.abc``.