Skip to content

Commit daed07a

Browse files
miss-islingtonbrettcannonhugovk
authored
[3.14] GH-137426: Remove code deprecation of importlib.abc.ResourceLoader (GH-137567) (#137654)
Co-authored-by: Brett Cannon <[email protected]> Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent 946b226 commit daed07a

File tree

4 files changed

+12
-38
lines changed

4 files changed

+12
-38
lines changed

Doc/library/importlib.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ ABC hierarchy::
393393
.. deprecated:: 3.7
394394
This ABC is deprecated in favour of supporting resource loading
395395
through :class:`importlib.resources.abc.TraversableResources`.
396+
This class exists for backwards compatibility only with other ABCs in
397+
this module.
396398

397399
.. method:: get_data(path)
398400
:abstractmethod:

Lib/importlib/abc.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,14 @@ def invalidate_caches(self):
6464
class ResourceLoader(Loader):
6565

6666
"""Abstract base class for loaders which can return data from their
67-
back-end storage.
67+
back-end storage to facilitate reading data to perform an import.
6868
6969
This ABC represents one of the optional protocols specified by PEP 302.
7070
71-
"""
72-
73-
def __init__(self):
74-
import warnings
75-
warnings.warn('importlib.abc.ResourceLoader is deprecated in '
76-
'favour of supporting resource loading through '
77-
'importlib.resources.abc.TraversableResources.',
78-
DeprecationWarning, stacklevel=2)
79-
super().__init__()
71+
For directly loading resources, use TraversableResources instead. This class
72+
primarily exists for backwards compatibility with other ABCs in this module.
8073
74+
"""
8175

8276
@abc.abstractmethod
8377
def get_data(self, path):

Lib/test/test_importlib/test_abc.py

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,7 @@ class ResourceLoaderDefaultsTests(ABCTestHarness):
224224
SPLIT = make_abc_subclasses(ResourceLoader)
225225

226226
def test_get_data(self):
227-
with (
228-
self.assertRaises(IOError),
229-
self.assertWarnsRegex(
230-
DeprecationWarning,
231-
r"importlib\.abc\.ResourceLoader is deprecated in favour of "
232-
r"supporting resource loading through importlib\.resources"
233-
r"\.abc\.TraversableResources.",
234-
),
235-
):
227+
with self.assertRaises(IOError):
236228
self.ins.get_data('/some/path')
237229

238230

@@ -936,13 +928,8 @@ def get_filename(self, fullname):
936928

937929
def path_stats(self, path):
938930
return {'mtime': 1}
939-
with self.assertWarnsRegex(
940-
DeprecationWarning,
941-
r"importlib\.abc\.ResourceLoader is deprecated in favour of "
942-
r"supporting resource loading through importlib\.resources"
943-
r"\.abc\.TraversableResources.",
944-
):
945-
loader = DummySourceLoader()
931+
932+
loader = DummySourceLoader()
946933

947934
with self.assertWarnsRegex(
948935
DeprecationWarning,
@@ -952,17 +939,5 @@ def path_stats(self, path):
952939
loader.path_mtime('foo.py')
953940

954941

955-
class ResourceLoaderDeprecationWarningsTests(unittest.TestCase):
956-
"""Tests ResourceLoader deprecation warnings."""
957-
958-
def test_deprecated_resource_loader(self):
959-
from importlib.abc import ResourceLoader
960-
class DummyLoader(ResourceLoader):
961-
def get_data(self, path):
962-
return b''
963-
964-
with self.assertWarns(DeprecationWarning):
965-
DummyLoader()
966-
967942
if __name__ == '__main__':
968943
unittest.main()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Remove the code deprecation of ``importlib.abc.ResourceLoader``. It is
2+
documented as deprecated, but left for backwards compatibility with other
3+
classes in ``importlib.abc``.

0 commit comments

Comments
 (0)