8000 gh-121604: Make sure all deprecated items in importlib raise DeprecationWarning by tomasr8 · Pull Request #128007 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add DeprecationWarning for path_mtime
Co-authored-by: rashansmith <smith.rashan@gmail.com>
  • Loading branch information
tomasr8 and rashansmith committed Dec 16, 2024
commit d4844c54419a69f417144d4bfe0aeb9787b9cea3
5 changes: 5 additions & 0 deletions Lib/importlib/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ 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'])
Expand Down
20 changes: 20 additions & 0 deletions Lib/test/test_importlib/test_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,5 +913,25 @@ def test_universal_newlines(self):
SourceOnlyLoaderMock=SPLIT_SOL)


class SourceLoaderDeprecationWarningsTests(unittest.TestCase):
"""Tests SourceLoader deprecation warnings."""

def test_deprecated_path_mtime(self):
from importlib.abc import SourceLoader
class DummySourceLoader(SourceLoader):
def get_data(self, path):
return b''

def get_filename(self, fullname):
return 'foo.py'

def path_stats(self, path):
return {'mtime': 1}

loader = DummySourceLoader()
with self.assertWarns(DeprecationWarning):
loader.path_mtime('foo.py')


if __name__ == '__main__':
unittest.main()
0