mirror of
https://github.com/python/cpython.git
synced 2025-11-09 10:01:42 +00:00
[3.14] GH-137426: Remove code deprecation of importlib.abc.ResourceLoader (GH-137567) (#137654)
Co-authored-by: Brett Cannon <brett@python.org> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
This commit is contained in:
parent
946b226b90
commit
daed07a1f9
4 changed files with 12 additions and 38 deletions
|
|
@ -393,6 +393,8 @@ ABC hierarchy::
|
||||||
.. deprecated:: 3.7
|
.. deprecated:: 3.7
|
||||||
This ABC is deprecated in favour of supporting resource loading
|
This ABC is deprecated in favour of supporting resource loading
|
||||||
through :class:`importlib.resources.abc.TraversableResources`.
|
through :class:`importlib.resources.abc.TraversableResources`.
|
||||||
|
This class exists for backwards compatibility only with other ABCs in
|
||||||
|
this module.
|
||||||
|
|
||||||
.. method:: get_data(path)
|
.. method:: get_data(path)
|
||||||
:abstractmethod:
|
:abstractmethod:
|
||||||
|
|
|
||||||
|
|
@ -64,21 +64,15 @@ def invalidate_caches(self):
|
||||||
class ResourceLoader(Loader):
|
class ResourceLoader(Loader):
|
||||||
|
|
||||||
"""Abstract base class for loaders which can return data from their
|
"""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.
|
This ABC represents one of the optional protocols specified by PEP 302.
|
||||||
|
|
||||||
|
For directly loading resources, use TraversableResources instead. This class
|
||||||
|
primarily exists for backwards compatibility with other ABCs in this module.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
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__()
|
|
||||||
|
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_data(self, path):
|
def get_data(self, path):
|
||||||
"""Abstract method which when implemented should return the bytes for
|
"""Abstract method which when implemented should return the bytes for
|
||||||
|
|
|
||||||
|
|
@ -224,15 +224,7 @@ class ResourceLoaderDefaultsTests(ABCTestHarness):
|
||||||
SPLIT = make_abc_subclasses(ResourceLoader)
|
SPLIT = make_abc_subclasses(ResourceLoader)
|
||||||
|
|
||||||
def test_get_data(self):
|
def test_get_data(self):
|
||||||
with (
|
with self.assertRaises(IOError):
|
||||||
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.",
|
|
||||||
),
|
|
||||||
):
|
|
||||||
self.ins.get_data('/some/path')
|
self.ins.get_data('/some/path')
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -936,12 +928,7 @@ def get_filename(self, fullname):
|
||||||
|
|
||||||
def path_stats(self, path):
|
def path_stats(self, path):
|
||||||
return {'mtime': 1}
|
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(
|
with self.assertWarnsRegex(
|
||||||
|
|
@ -952,17 +939,5 @@ def path_stats(self, path):
|
||||||
loader.path_mtime('foo.py')
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
|
|
@ -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…
Add table
Add a link
Reference in a new issue