[pep8-naming] Check naming conventions in match pattern bindings (N806, N815, N816)#23899
Merged
ntBre merged 3 commits intoastral-sh:mainfrom Mar 12, 2026
Merged
Conversation
…815, N816) N806, N815, and N816 only checked variable names in assignment expressions (Expr::Name with Store context), missing variables bound through match/case patterns (MatchAs, MatchStar, and MatchMapping rest captures). Refactor the three rule functions to accept TextRange instead of &Expr (they only used expr.range()), add an analyze::pattern module that extracts bound names from patterns and runs the same checks, and wire it into the visitor's visit_pattern method. Fixes astral-sh#16502
…e/expression.rs" This reverts commit a011b2e.
Contributor
|
(Sorry clicked the wrong button in the refined-github menu and reverted changes to a file) |
|
pep8-naming] Check naming conventions in match pattern bindings (N806, N815, N816)
ntBre
approved these changes
Mar 12, 2026
Contributor
ntBre
left a comment
There was a problem hiding this comment.
Makes sense to me, thank you!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Fixes #16502
N806, N815, and N816 had false negatives for variables bound in
match/casepatterns. The rules only checkedExpr::Namenodes withExprContext::Store, but match patterns bind variables throughPatternnodes (MatchAs,MatchStar,MatchMappingrest captures), which were not checked.Changes
TextRangeinstead of&Expr(they only usedexpr.range())analyze::patternmodule that extracts bound names from match patterns and runs the same naming checksvisit_patternvisitor methodNow all three rules flag violations in:
case Name:(capture pattern)case int(Name):(class pattern keyword)case [*Name]:(star pattern)case pattern as Name:(as pattern)case {"key": 1, **Name}:(mapping rest)Test plan
cargo clippy -p ruff_linter -- -D warnings)