Do not treat a walrus argument as a keyword argument - #242
Merged
davidhalter merged 1 commit intoJul 31, 2026
Merged
Conversation
f(a := 1, b) was reported as "positional argument follows keyword argument". _ArglistRule inspected only the argument node's first child, so a named expression (name := value) looked identical to a keyword argument (name = value) and set kw_only, making every following positional argument an error. Distinguish the two by the operator child, and add the case to the existing test_valid_namedexpr parametrize list. Closes davidhalter#212
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.
Closes #212
f(a := 1, b)was reported asSyntaxError: positional argument follows keyword argument._ArglistRulelooked only at the argument node's first child, so a named expression (name := value) was indistinguishable from a keyword argument (name = value) and setkw_only, making every following positional argument an error. Checking the operator child separates the two; thef(**x, y),f(x=2, y)and generator-expression cases are unaffected.The two cases are added to the existing
test_valid_namedexprparametrize list; they fail without the fix and pass with it (full suite: 1988 passed).This change was prepared with AI assistance; the regression test was run locally and fails without the fix.