PEP 845: Leading-Dot Value Patterns
PEP 845 introduces a new syntax allowing local and global variables to be used as value patterns in match statements via a leading-dot prefix. This eliminates the requirement for guard clauses when matching against non-attribute names.
Verified State Diff
Impact & Verification Analysis
Python developers utilizing structural pattern matching in Python 3.x.
It simplifies code readability and reduces the reliance on verbose guard clauses, making pattern matching more idiomatic for standard variable comparisons.
Full Fact Overview
The implementation of PEP 845 modifies the Python pattern matching mechanism to resolve names prefixed with a dot (.) using standard scope resolution rules rather than treating them as capture patterns. Previously, match statements required either attribute access (e.g., Module.CONSTANT) or guard clauses (if x == local_var) to compare a subject against a variable defined in the current scope. By enabling '.name' syntax, the language reduces boilerplate code and improves the ergonomics of structural pattern matching for complex conditional logic.