Skip to content

Commit

Permalink
gh-93963: Officially deprecate abcs and warn about their usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jun 17, 2022
1 parent 96464e5 commit 5e7fb9c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
26 changes: 21 additions & 5 deletions Lib/importlib/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Officially deprecate from ``importlib.abc`` classes moved to
``importlib.resources.abc``.

0 comments on commit 5e7fb9c

Please sign in to comment.