Skip to content

Conversation

@TTsangSC
Copy link
Collaborator

@TTsangSC TTsangSC commented Oct 25, 2025

Closes #405.

Summary

This fixes the edge cases which occur for Python 3.11 (and older patch versions of 3.12; see e.g.: python/cpython#116608; python/cpython#132206) where line_profiler.toml_config emits a DeprecationWarning (example in pipeline) because we used importlib.resources.path(). Now the code is reworked to prefer the newer importlib.resources.files() wherever available (i.e. not on Python 3.8).

A test (tests/test_toml_config.py::test_importlib_resources_deprecation()) is also added to ensure that the warning is not emitted; the test fails on Python 3.11 on main, as it should.

Acknowledgements

Thanks to @user202729 and @JostMigenda for correcting my mis-construal of the original issue and misconceptions about importlib.resources and its history.

Thanks to @Erotemic as always for discussions regarding general maintenance of the repo (versioning, legacy-version support, etc.), and probably later reviewing this PR ;)

Note

The PR has been significantly rewritten; see commit and edit histories.

@TTsangSC TTsangSC changed the title FiX: importlib_resources-related edge cases FIX: importlib_resources-related edge cases Oct 25, 2025
@TTsangSC TTsangSC changed the title FIX: importlib_resources-related edge cases DRAFT: FIX: importlib_resources-related edge cases Oct 25, 2025
@codecov
Copy link

codecov bot commented Oct 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.28%. Comparing base (60e928f) to head (d5e0886).
⚠️ Report is 22 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #406      +/-   ##
==========================================
+ Coverage   87.56%   90.28%   +2.71%     
==========================================
  Files          18       20       +2     
  Lines        1641     2080     +439     
  Branches      348      447      +99     
==========================================
+ Hits         1437     1878     +441     
- Misses        149      151       +2     
+ Partials       55       51       -4     
Files with missing lines Coverage Δ
line_profiler/toml_config.py 93.79% <100.00%> (ø)

... and 4 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1219bc0...d5e0886. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TTsangSC TTsangSC changed the title DRAFT: FIX: importlib_resources-related edge cases FIX: importlib_resources-related edge cases Oct 25, 2025
@TTsangSC TTsangSC changed the title FIX: importlib_resources-related edge cases FIX: importlib.resources-related edge cases Nov 9, 2025
tests/test_toml_config.py
    - Removed venv setup code
    - Refactored `test_backported_importlib_resources()` into
      `test_importlib_resources_deprecation()`, which now just uses the
      vanilla `importlib.resources`;
      test fails for Python 3.11 pre-PR, as it should
@TTsangSC TTsangSC changed the title FIX: importlib.resources-related edge cases FIX: DeprecationWarning emitted by how line_profiler.toml_config uses importlib.resources Nov 19, 2025
@Erotemic
Copy link
Member

I think the discussion on this PR has matured in issue #405 @TTsangSC is this ready to merge? It looks good to me by reading the diff.

@TTsangSC
Copy link
Collaborator Author

Sorry, was sleeping like a log, so I didn't see your message. Just gave it one last look, rewrote a wrong comment, and I think it's ready to go. Thanks for the review!

@Erotemic Erotemic merged commit b66c42c into pyutils:main Nov 20, 2025
45 checks passed
@TTsangSC TTsangSC deleted the importlib-deprecation branch November 20, 2025 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DeprecationWarning: path is deprecated. Use files() instead.

2 participants