gh-121604: Make sure all deprecated items in importlib raise DeprecationWarning (#128007)

Co-authored-by: rashansmith <smith.rashan@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Brett Cannon <brett@python.org>
This commit is contained in:
Tomas R. 2025-01-15 01:48:46 +01:00 committed by GitHub
parent b52de22ac3
commit bd3baa8b1a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 96 additions and 5 deletions

View file

@ -70,6 +70,15 @@ class ResourceLoader(Loader):
"""
def __init__(self):
import warnings
warnings.warn('importlib.abc.ResourceLoader is deprecated in '
'favour of supporting resource loading through '
'importlib.resources.abc.ResourceReader.',
DeprecationWarning, stacklevel=2)
super().__init__()
@abc.abstractmethod
def get_data(self, path):
"""Abstract method which when implemented should return the bytes for
@ -199,6 +208,10 @@ class SourceLoader(_bootstrap_external.SourceLoader, ResourceLoader, ExecutionLo
def path_mtime(self, path):
"""Return the (int) modification time for the path (str)."""
import warnings
warnings.warn('SourceLoader.path_mtime is deprecated in favour of '
'SourceLoader.path_stats().',
DeprecationWarning, stacklevel=2)
if self.path_stats.__func__ is SourceLoader.path_stats:
raise OSError
return int(self.path_stats(path)['mtime'])