From 5e7fb9c749a06f4888aa9489ced4acb323c5a055 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 17 Jun 2022 15:59:21 -0400 Subject: [PATCH 1/5] 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``. From 63c3c76e0f7dbc4d99917ef4d4c9629e5db2c9dd Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 17 Jun 2022 17:30:38 -0400 Subject: [PATCH 2/5] Adopt better wording Co-authored-by: Thomas Grainger --- Lib/importlib/abc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py index 6bcc47f8271433..a468032bae592b 100644 --- a/Lib/importlib/abc.py +++ b/Lib/importlib/abc.py @@ -35,8 +35,8 @@ def __getattr__(name, canonical=_resources_abc): 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", + f"of from {canonical.__name__!r} is now deprecated, " + "scheduled for removal in Python 3.13", DeprecationWarning, stacklevel=2, ) From 85259269b02fa5cc651f8ee0e5ee80e52d26d6d2 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 3 Jul 2022 10:25:45 -0400 Subject: [PATCH 3/5] =?UTF-8?q?Use=20'warnings.=5Fdeprecated'.=20Fixes=20#?= =?UTF-8?q?93963=20until=20Python=20=CF=80.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lib/importlib/abc.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py index a468032bae592b..5f2e2f6bd05b44 100644 --- a/Lib/importlib/abc.py +++ b/Lib/importlib/abc.py @@ -28,18 +28,11 @@ def __getattr__(name, canonical=_resources_abc): """ For backwards compatibility, continue to make names - from canonical available through this module. + from canonical available through this module. #93963 """ 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 now deprecated, " - "scheduled for removal in Python 3.13", - DeprecationWarning, - stacklevel=2, - ) + warnings._deprecated(__name__, remove=(3, 14)) globals()[name] = obj return obj raise AttributeError(f'module {__name__!r} has no attribute {name!r}') From 529e6ea178cfbf95eb219152b12df8a8f753de56 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 3 Jul 2022 10:34:04 -0400 Subject: [PATCH 4/5] Remove generalization of a 'canonical' module and just repeat one's self --- Lib/importlib/abc.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py index 5f2e2f6bd05b44..396eeb2b198885 100644 --- a/Lib/importlib/abc.py +++ b/Lib/importlib/abc.py @@ -25,13 +25,13 @@ ] -def __getattr__(name, canonical=_resources_abc): +def __getattr__(name): """ For backwards compatibility, continue to make names - from canonical available through this module. #93963 + from _resources_abc available through this module. #93963 """ - if name in canonical.__all__: - obj = getattr(canonical, name) + if name in _resources_abc.__all__: + obj = getattr(_resources_abc, name) warnings._deprecated(__name__, remove=(3, 14)) globals()[name] = obj return obj From 908c96a76926443cc134fa05167e9d39170eb7ce Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 3 Jul 2022 10:38:26 -0400 Subject: [PATCH 5/5] =?UTF-8?q?Identify=20the=20attribute=20name,=20not=20?= =?UTF-8?q?just=20the=20module=20in=20which=20it=20appears=20=F0=9F=A4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Thomas Grainger --- Lib/importlib/abc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py index 396eeb2b198885..8fa9a0f3bc1e4b 100644 --- a/Lib/importlib/abc.py +++ b/Lib/importlib/abc.py @@ -32,7 +32,7 @@ def __getattr__(name): """ if name in _resources_abc.__all__: obj = getattr(_resources_abc, name) - warnings._deprecated(__name__, remove=(3, 14)) + warnings._deprecated(f"{__name__}.{name}", remove=(3, 14)) globals()[name] = obj return obj raise AttributeError(f'module {__name__!r} has no attribute {name!r}')