Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pep8-naming] Flag variables bound in match patterns (N806/N815/N816) #16882

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gopoto
Copy link

@gopoto gopoto commented Mar 21, 2025

Summary

Extend pep8-naming to catch mixed‑case identifiers introduced via structural
pattern matching:

  • N806: variables bound by a match pattern inside functions
  • N815: variables bound by a match pattern inside classes
  • N816: variables bound by a match pattern at module scope

Previously 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 and N816 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:

cargo clippy --workspace --all-targets --all-features -- -D warnings
RUFF_UPDATE_SCHEMA=1 cargo test
uvx pre-commit run --all-files --show-diff-on-failure

This PR was generated by an AI system in collaboration with maintainers: @carljm, @ntBre

@ntBre ntBre linked an issue Mar 21, 2025 that may be closed by this pull request
@ntBre ntBre added the bug Something isn't working label Mar 21, 2025
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

N806, N815, and N816 ignore case patterns
2 participants