Skip to content

Commit 5e7fb9c

Browse files
committed
gh-93963: Officially deprecate abcs and warn about their usage.
1 parent 96464e5 commit 5e7fb9c

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

Lib/importlib/abc.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,36 @@
1515
import abc
1616
import warnings
1717

18-
# for compatibility with Python 3.10
19-
from .resources.abc import ResourceReader, Traversable, TraversableResources
18+
from .resources import abc as _resources_abc
2019

2120

2221
__all__ = [
2322
'Loader', 'Finder', 'MetaPathFinder', 'PathEntryFinder',
2423
'ResourceLoader', 'InspectLoader', 'ExecutionLoader',
2524
'FileLoader', 'SourceLoader',
26-
27-
# for compatibility with Python 3.10
28-
'ResourceReader', 'Traversable', 'TraversableResources',
2925
]
3026

3127

28+
def __getattr__(name, canonical=_resources_abc):
29+
"""
30+
For backwards compatibility, continue to make names
31+
from canonical available through this module.
32+
"""
33+
if name in canonical.__all__:
34+
obj = getattr(canonical, name)
35+
import warnings
36+
warnings.warn(
37+
f"Using or importing the ABCs from {__name__!r} instead "
38+
f"of from {canonical.__name__!r} is deprecated since "
39+
"Python 3.11, and in 3.13 it will stop working",
40+
DeprecationWarning,
41+
stacklevel=2,
42+
)
43+
globals()[name] = obj
44+
return obj
45+
raise AttributeError(f'module {__name__!r} has no attribute {name!r}')
46+
47+
3248
def _register(abstract_cls, *classes):
3349
for cls in classes:
3450
abstract_cls.register(cls)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Officially deprecate from ``importlib.abc`` classes moved to
2+
``importlib.resources.abc``.

0 commit comments

Comments
 (0)