Skip to content

Commit cbe54a3

Browse files
tomasr8rashansmith
andcommitted
Add DeprecationWarning for ResourceLoader
Co-authored-by: rashansmith <[email protected]>
1 parent d4844c5 commit cbe54a3

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Lib/importlib/abc.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ class ResourceLoader(Loader):
7070
7171
"""
7272

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.ResourceReader.",
78+
DeprecationWarning, stacklevel=2)
79+
super().__init__()
80+
81+
7382
@abc.abstractmethod
7483
def get_data(self, path):
7584
"""Abstract method which when implemented should return the bytes for

Lib/test/test_importlib/test_abc.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,5 +933,13 @@ def path_stats(self, path):
933933
loader.path_mtime('foo.py')
934934

935935

936+
class ResourceLoaderDeprecationWarningsTests(unittest.TestCase):
937+
"""Tests ResourceLoader deprecation warnings."""
938+
939+
def test_deprecated_resource_loader(self):
940+
with self.assertWarns(DeprecationWarning):
941+
from importlib.abc import ResourceLoader
942+
943+
936944
if __name__ == '__main__':
937945
unittest.main()

0 commit comments

Comments
 (0)