Skip to content

Commit d4844c5

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

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Lib/importlib/abc.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ class SourceLoader(_bootstrap_external.SourceLoader, ResourceLoader, ExecutionLo
199199

200200
def path_mtime(self, path):
201201
"""Return the (int) modification time for the path (str)."""
202+
import warnings
203+
warnings.warn("SourceLoader.path_mtime is deprecated in favour of "
204+
"SourceLoader.path_stats().",
205+
DeprecationWarning,
206+
stacklevel=2)
202207
if self.path_stats.__func__ is SourceLoader.path_stats:
203208
raise OSError
204209
return int(self.path_stats(path)['mtime'])

Lib/test/test_importlib/test_abc.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,5 +913,25 @@ def test_universal_newlines(self):
913913
SourceOnlyLoaderMock=SPLIT_SOL)
914914

915915

916+
class SourceLoaderDeprecationWarningsTests(unittest.TestCase):
917+
"""Tests SourceLoader deprecation warnings."""
918+
919+
def test_deprecated_path_mtime(self):
920+
from importlib.abc import SourceLoader
921+
class DummySourceLoader(SourceLoader):
922+
def get_data(self, path):
923+
return b''
924+
925+
def get_filename(self, fullname):
926+
return 'foo.py'
927+
928+
def path_stats(self, path):
929+
return {'mtime': 1}
930+
931+
loader = DummySourceLoader()
932+
with self.assertWarns(DeprecationWarning):
933+
loader.path_mtime('foo.py')
934+
935+
916936
if __name__ == '__main__':
917937
unittest.main()

0 commit comments

Comments
 (0)