Skip to content

Do not treat a walrus argument as a keyword argument - #242

Merged
davidhalter merged 1 commit into
davidhalter:masterfrom
Sanjays2402:fix/walrus-not-keyword-argument
Jul 31, 2026
Merged

Do not treat a walrus argument as a keyword argument#242
davidhalter merged 1 commit into
davidhalter:masterfrom
Sanjays2402:fix/walrus-not-keyword-argument

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

Closes #212

f(a := 1, b) was reported as SyntaxError: positional argument follows keyword argument. _ArglistRule looked only at the argument node's first child, so a named expression (name := value) was indistinguishable from a keyword argument (name = value) and set kw_only, making every following positional argument an error. Checking the operator child separates the two; the f(**x, y), f(x=2, y) and generator-expression cases are unaffected.

The two cases are added to the existing test_valid_namedexpr parametrize 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.

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
@davidhalter
davidhalter merged commit 7f5b142 into davidhalter:master Jul 31, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Walrus causes unnecessary SyntaxError

2 participants