Repository navigation
gh-163121: Fix _= in a class pattern after a positional pattern - #163126
Open
Robertboy18 wants to merge 1 commit into
Open
Robertboy18 wants to merge 1 commit into
Robertboy18 wants to merge 1 commit into
Conversation
Robertboy18
requested review from
brandtbucher,
lysnikolaou and
pablogsal
as code owners
December 4, 2026 03:39
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.
@gvanrossum here's the fix for #163121 :)
The problem was that
wildcard_patternis just"_", whilepattern_capture_targetandvalue_patternboth have a!('.' | '(' | '=')lookahead. So incase C(p, _=x):,positional_patternstook the_as a wildcard and then got stuck at the=. This adds!'='towildcard_pattern(and regeneratesParser/parser.c), so_=xis parsed as a keyword pattern like any other name. I only added the=part, socase _.x:andcase _(a):stay syntax errors, as they are now.Since a pattern is never followed by
=in valid code, nothing that compiled before changes. A few errors for invalid class patterns do change, and they now match what any other keyword name gives. E.g.case C(p, _=x, q):now says "positional patterns follow keyword patterns", likecase C(p, a=x, q):, instead of "invalid syntax".The new tests in
test_patmaandtest_syntaxboth fail on main.I used AI tools to help write and review the patch, and checked it myself.
_as a keyword name in a class pattern raises a SyntaxError right after a positional pattern #163121