https://github.com/python/cpython/commit/7140b99b0d0952167f7fdd747e6c28a8c8a2d768
commit: 7140b99b0d0952167f7fdd747e6c28a8c8a2d768
branch: main
author: Brett Cannon <br...@python.org>
committer: brettcannon <br...@python.org>
date: 2025-08-11T16:18:54-07:00
summary:

GH-137426: Remove code deprecation of `importlib.abc.ResourceLoader` (GH-137567)

Enough other classes in `importlib.abc` inherit from the class and the 
deprecation was to redirect people to `TraversableResources`. The documentation 
now makes it clear the class only exists for backwards compatibility.

---------

Co-authored-by: Hugo van Kemenade <1324225+hug...@users.noreply.github.com>

files:
A Misc/NEWS.d/next/Library/2025-08-08-15-00-38.gh-issue-137426.lW-Rk2.rst
M Doc/library/importlib.rst
M Lib/importlib/abc.py
M Lib/test/test_importlib/test_abc.py

diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst
index 4f374be778d6b3..ddf503af82d988 100644
--- a/Doc/library/importlib.rst
+++ b/Doc/library/importlib.rst
@@ -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:
diff --git a/Lib/importlib/abc.py b/Lib/importlib/abc.py
index 29f01f77eff4a0..1e47495f65fa02 100644
--- a/Lib/importlib/abc.py
+++ b/Lib/importlib/abc.py
@@ -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):
diff --git a/Lib/test/test_importlib/test_abc.py 
b/Lib/test/test_importlib/test_abc.py
index 070920d0da7e19..dd943210ffca3c 100644
--- a/Lib/test/test_importlib/test_abc.py
+++ b/Lib/test/test_importlib/test_abc.py
@@ -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')
 
 
@@ -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,
@@ -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()
diff --git 
a/Misc/NEWS.d/next/Library/2025-08-08-15-00-38.gh-issue-137426.lW-Rk2.rst 
b/Misc/NEWS.d/next/Library/2025-08-08-15-00-38.gh-issue-137426.lW-Rk2.rst
new file mode 100644
index 00000000000000..6d05c8a3bf4e4e
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-08-08-15-00-38.gh-issue-137426.lW-Rk2.rst
@@ -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``.

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: arch...@mail-archive.com

Reply via email to