Reject _ as a match-pattern target - #25977
Conversation
Memory usage reportMemory usage unchanged ✅ |
|
|
376c134 to
2a6ce00
Compare
|
I'm not sure using semantic syntax errors is appropriate here, given that |
2a6ce00 to
c23c3c2
Compare
c23c3c2 to
70fb60f
Compare
Merging this PR will degrade performance by 4.52%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression with the CodSpeed MCP and your agent. Comparing |
70fb60f to
53bd691
Compare
MichaReiser
left a comment
There was a problem hiding this comment.
Thanks. Would you mind updating the summary before landing
Summary
Python reserves
_for wildcard patterns and does not allow it as the binding target in either of these forms:We currently recover an AST for both forms without reporting a parser error. Both are grammar errors in CPython, so this change validates the capture target while parsing
asand mapping patterns and reportscannot use '_' as a targeton the underscore.We previously tried to address the mapping-pattern case in #6838 by representing the rest target as a general
PatternMatchAsnode. This keeps the existingIdentifierrepresentation and recovered AST, including statements after the invalid match, while rejecting the invalid target at the parser boundary.