Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Simon Ruggier (@sruggier)
Tim Gates (@timgates42) <tim.gates@iress.com>
Batuhan Taskaya (@isidentical) <isidentical@gmail.com>
Jocelyn Boullier (@Kazy) <jocelyn@boullier.bzh>
Apoorv Darshan (@apoorvdarshan) <ad13dtu@gmail.com>


Note: (@user) means a github user name.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Changelog
Unreleased
++++++++++

- Fix a false ``SyntaxError`` for named expressions used as positional
arguments in a call, e.g. ``f(a := 1, b)``

0.8.7 (2026-05-02)
++++++++++++++++++

Expand Down
12 changes: 12 additions & 0 deletions parso/python/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,18 @@ def is_issue(self, node):
self.add_issue(argument, message=message)
else:
kw_unpacking_only = True
elif argument.children[1] == ':=':
# f(a := 1) is a named expression, i.e. a positional
# argument, not a keyword argument.
if kw_unpacking_only:
# f(**x, a := 1)
message = "positional argument follows " \
"keyword argument unpacking"
self.add_issue(argument, message=message)
elif kw_only:
# f(x=2, a := 1)
message = "positional argument follows keyword argument"
self.add_issue(argument, message=message)
else: # Is a keyword argument.
kw_only = True
if first.type == 'name':
Expand Down
2 changes: 2 additions & 0 deletions test/failing_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def build_nested(code, depth, base='def f():\n'):
'f(x=1, x=2)',
'f(**x, y)',
'f(x=2, y)',
'f(x=2, a := 1)',
'f(**x, a := 1)',
'f(**x, *y)',
'f(**x, y=3, z)',
# augassign
Expand Down
6 changes: 6 additions & 0 deletions test/test_python_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,12 @@ def test_valid_fstrings(code):
'a[(b:=0)]',
'a[(b:=0, c:=0)]',
'a[(b:=0):1:2]',
'f(a := 1, b)',
'f(a := 1, b=2)',
'f(a := 1, *b)',
'f(a := 1, **b)',
'f(b, a := 1)',
'f(*b, a := 1)',
]
)
def test_valid_namedexpr(code):
Expand Down
Loading