ruff
728b9d6f - [`pep8-naming`] Check naming conventions in `match` pattern bindings (`N806`, `N815`, `N816`) (#23899)

Commit
78 days ago
[`pep8-naming`] Check naming conventions in `match` pattern bindings (`N806`, `N815`, `N816`) (#23899) ## Summary Fixes #16502 N806, N815, and N816 had false negatives for variables bound in `match`/`case` patterns. The rules only checked `Expr::Name` nodes with `ExprContext::Store`, but match patterns bind variables through `Pattern` nodes (`MatchAs`, `MatchStar`, `MatchMapping` rest captures), which were not checked. ## Changes - Refactored rule functions to accept `TextRange` instead of `&Expr` (they only used `expr.range()`) - Added `analyze::pattern` module that extracts bound names from match patterns and runs the same naming checks - Wired the analysis into the existing `visit_pattern` visitor method Now 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 - [x] Added test cases to N806.py, N815.py, and N816.py fixture files - [x] Updated snapshots showing new violations detected - [x] All 52 pep8_naming tests pass - [x] Clippy clean (`cargo clippy -p ruff_linter -- -D warnings`)
Author
Parents
Loading