Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions Doc/library/importlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ ABC hierarchy::
.. deprecated:: 3.7
This ABC is deprecated in favour of supporting resource loading
through :class:`importlib.resources.abc.TraversableResources`.
This class exists for backwards compatibility only with other ABCs in
this module.

.. method:: get_data(path)
:abstractmethod:
Expand Down
14 changes: 4 additions & 10 deletions Lib/importlib/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,14 @@ def invalidate_caches(self):
class ResourceLoader(Loader):

"""Abstract base class for loaders which can return data from their
back-end storage.
back-end storage to facilitate reading data to perform an import.

This ABC represents one of the optional protocols specified by PEP 302.

"""

def __init__(self):
import warnings
warnings.warn('importlib.abc.ResourceLoader is deprecated in '
'favour of supporting resource loading through '
'importlib.resources.abc.TraversableResources.',
DeprecationWarning, stacklevel=2)
super().__init__()
For directly loading resources, use TraversableResources instead. This class
primarily exists for backwards compatibility with other ABCs in this module.

"""

@abc.abstractmethod
def get_data(self, path):
Expand Down
31 changes: 3 additions & 28 deletions Lib/test/test_importlib/test_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,7 @@ class ResourceLoaderDefaultsTests(ABCTestHarness):
SPLIT = make_abc_subclasses(ResourceLoader)

def test_get_data(self):
with (
self.assertRaises(IOError),
self.assertWarnsRegex(
DeprecationWarning,
r"importlib\.abc\.ResourceLoader is deprecated in favour of "
r"supporting resource loading through importlib\.resources"
r"\.abc\.TraversableResources.",
),
):
with self.assertRaises(IOError):
self.ins.get_data('/some/path')


Expand Down Expand Up @@ -936,13 +928,8 @@ def get_filename(self, fullname):

def path_stats(self, path):
return {'mtime': 1}
with self.assertWarnsRegex(
DeprecationWarning,
r"importlib\.abc\.ResourceLoader is deprecated in favour of "
r"supporting resource loading through importlib\.resources"
r"\.abc\.TraversableResources.",
):
loader = DummySourceLoader()

loader = DummySourceLoader()

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


class ResourceLoaderDeprecationWarningsTests(unittest.TestCase):
"""Tests ResourceLoader deprecation warnings."""

def test_deprecated_resource_loader(self):
from importlib.abc import ResourceLoader
class DummyLoader(ResourceLoader):
def get_data(self, path):
return b''

with self.assertWarns(DeprecationWarning):
DummyLoader()

if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Remove the code deprecation of importlib.abc.ResourceLoader . It is
documented as deprecated, but left for backwards compatibility with other
classes in importlib.abc.
Loading