Skip to content

Fix PLR1733 and PLR1736 loop false positives#25206

Open
ya-nsh wants to merge 1 commit into
astral-sh:mainfrom
ya-nsh:fix/plr1733-plr1736-loop-fps
Open

Fix PLR1733 and PLR1736 loop false positives#25206
ya-nsh wants to merge 1 commit into
astral-sh:mainfrom
ya-nsh:fix/plr1733-plr1736-loop-fps

Conversation

@ya-nsh
Copy link
Copy Markdown

@ya-nsh ya-nsh commented May 17, 2026

Summary

  • skip PLR1736 diagnostics in for/else blocks, matching the existing PLR1733 behavior
  • treat nested for targets that rebind the index or value variable as modifications, avoiding unsafe PLR1733/PLR1736 replacements after shadowing
  • add regression coverage for loop-else and shadowed loop variables

Closes #25182.

Test Plan

  • CARGO_PROFILE_DEV_OPT_LEVEL=1 CARGO_PROFILE_DEV_DEBUG=line-tables-only INSTA_UPDATE=always INSTA_FORCE_PASS=1 cargo test -p ruff_linter rules::pylint::tests::rules -- PLR1733_unnecessary_dict_index_lookup.py PLR1736_unnecessary_list_index_lookup.py
  • cargo fmt --check
  • uvx prek run --files crates/ruff_linter/src/rules/pylint/helpers.rs crates/ruff_linter/src/rules/pylint/rules/unnecessary_list_index_lookup.rs crates/ruff_linter/resources/test/fixtures/pylint/unnecessary_dict_index_lookup.py crates/ruff_linter/resources/test/fixtures/pylint/unnecessary_list_index_lookup.py crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR1736_unnecessary_list_index_lookup.py.snap

@astral-sh-bot astral-sh-bot Bot requested a review from ntBre May 17, 2026 07:46
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.

Additional false positives in PLR1733 and PLR1736

2 participants