[pep8-naming] Flag variables bound in match patterns (N806/N815/N816) #16882
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Extend
pep8-naming
to catch mixed‑case identifiers introduced via structuralpattern matching:
N806
: variables bound by amatch
pattern inside functionsN815
: variables bound by amatch
pattern inside classesN816
: variables bound by amatch
pattern at module scopePreviously these names were ignored since they weren’t visited during
expression store analysis. Add a pattern walker that binds pattern names and
runs the same naming checks based on the current scope. Test fixtures and
snapshots for
N806
,N815
andN816
have been updated with match cases.Test Plan
Run Ruff against the
pep8_naming
fixtures:cargo run -p ruff -- check crates/ruff_linter/resources/test/fixtures/pep8_naming/N806.py --select N806 --no-cache
The added pattern variables are now flagged. All unit and integration tests pass
after updating the affected snapshots:
This PR was generated by an AI system in collaboration with maintainers: @carljm, @ntBre