pypdf icon indicating copy to clipboard operation
pypdf copied to clipboard

MAINT: Enforce PLW2901 (avoid loop/context var overwrite)

Open dev-KingMaster opened this issue 1 month ago • 4 comments

Summary

  • Removes PLW2901 ignore and fixes all instances where loop or context-manager variables were overwritten, improving readability and avoiding subtle bugs.
  • Why: Aligns with Ruff “no var overwrite” guidance; safer, clearer code; progresses #3327.
  • Scope: Touches core modules (e.g., pypdf/_cmap.py, _doc_common.py, _page.py, _writer.py, _text_extraction/_layout_mode/_font.py, filters.py, generic/_files.py) and a few tests where the pattern occurred.
  • Approach: Introduces new local names (*_obj, *_val, operands_for_tm, etc.) instead of reassigning loop/context variables; no behavioral changes.
  • Config: Removes "PLW2901" from [tool.ruff.lint].ignore in pyproject.toml.
  • Validation: ruff check passes cleanly with PLW2901 enforced. No functional logic altered; tests adjusted only for variable naming where needed.

Contribution by Gittensor, learn more at https://gittensor.io/

dev-KingMaster avatar Nov 05 '25 13:11 dev-KingMaster

Codecov Report

:x: Patch coverage is 98.14815% with 1 line in your changes missing coverage. Please review. :white_check_mark: Project coverage is 97.11%. Comparing base (85b53d8) to head (d1e8189).

Files with missing lines Patch % Lines
pypdf/_doc_common.py 92.30% 0 Missing and 1 partial :warning:
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3513   +/-   ##
=======================================
  Coverage   97.11%   97.11%           
=======================================
  Files          57       57           
  Lines        9713     9714    +1     
  Branches     1758     1756    -2     
=======================================
+ Hits         9433     9434    +1     
  Misses        168      168           
  Partials      112      112           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

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

codecov[bot] avatar Nov 05 '25 13:11 codecov[bot]

Hi @stefan6419846 I addressed all the comments.

dev-KingMaster avatar Nov 05 '25 16:11 dev-KingMaster

Resolved all comments. @stefan6419846

dev-KingMaster avatar Nov 06 '25 16:11 dev-KingMaster

Addressed comments. @stefan6419846

dev-KingMaster avatar Nov 11 '25 13:11 dev-KingMaster