Skip to content

Conversation

@dev-KingMaster
Copy link

@dev-KingMaster dev-KingMaster commented Nov 5, 2025

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 Cleanup ruff ignores #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 dev-KingMaster changed the title Ruff cleanup: enforce PLW2901 (no loop/context var overwrite) MAINT: Enforce PLW2901 (avoid loop/context var overwrite) (#3327) Nov 5, 2025
@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

❌ Patch coverage is 98.38710% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.10%. Comparing base (3b5c85f) to head (e385405).

Files with missing lines Patch % Lines
pypdf/_doc_common.py 92.30% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3513   +/-   ##
=======================================
  Coverage   97.10%   97.10%           
=======================================
  Files          57       57           
  Lines        9711     9718    +7     
  Branches     1759     1759           
=======================================
+ Hits         9430     9437    +7     
  Misses        168      168           
  Partials      113      113           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@stefan6419846 stefan6419846 changed the title MAINT: Enforce PLW2901 (avoid loop/context var overwrite) (#3327) MAINT: Enforce PLW2901 (avoid loop/context var overwrite) Nov 5, 2025
Copy link
Collaborator

@stefan6419846 stefan6419846 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I have left some remarks for specific changes and some general ones.

@dev-KingMaster
Copy link
Author

Hi @stefan6419846 I addressed all the comments.

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.

2 participants