Skip to content
Open
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
3 changes: 3 additions & 0 deletions Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,9 @@ invalid_expression:
RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "t-string: lambda expressions are not allowed without parentheses") }

invalid_named_expression(memo):
| '(' a=NAME ')' ':=' expression {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
a, "cannot parenthesize target name in assignment expression") }
| a=expression ':=' expression {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
a, "cannot use assignment expressions with %s", _PyPegen_get_expr_name(a)) }
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -2686,6 +2686,13 @@ def f(x: *b)
>>> f(x = 5, *:)
Traceback (most recent call last):
SyntaxError: Invalid star expression

Invalid assignment expressions with parenthesized targets:

>>> ((a) := 1)
Traceback (most recent call last):
...
SyntaxError: cannot parenthesize target name in assignment expression
"""

import re
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Raise an improved :exc:`SyntaxError` when using parentheses around a walrus target.
37 changes: 37 additions & 0 deletions Parser/parser.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading