8000 gh-93963: Officially deprecate abcs and warn about their usage. by jaraco · Pull Request #93965 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-93963: Officially deprecate abcs and warn about their usage. #93965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 3, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 now deprecated, "
"scheduled for removal in Python 3.13",
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