Skip to content

Commit d385c29

Browse files
Update Grammar/python.gram
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
1 parent 445c7fd commit d385c29

File tree

5 files changed

+219
-132
lines changed

5 files changed

+219
-132
lines changed

Grammar/python.gram

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,11 +640,21 @@ invalid_assignment:
640640
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "only single target (not tuple) can be annotated") }
641641
| a=expression ':' expression ['=' annotated_rhs] {
642642
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "illegal target for annotation") }
643-
| a=expression ('=' | augassign) (yield_expr | star_expressions) {
643+
| a=star_expressions '=' (yield_expr | star_expressions) {
644644
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
645645
_PyPegen_get_invalid_target(a),
646646
"cannot assign to %s", _PyPegen_get_expr_name(_PyPegen_get_invalid_target(a))
647647
)}
648+
| a=expression augassign (yield_expr | star_expressions) {
649+
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
650+
_PyPegen_get_invalid_target(a),
651+
"cannot assign to %s", _PyPegen_get_expr_name(_PyPegen_get_invalid_target(a))
652+
)}
653+
| a=star_expressions augassign (yield_expr | star_expressions) {
654+
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
655+
a,
656+
"illegal expression for augmented assignment"
657+
)}
648658
invalid_block:
649659
| NEWLINE !INDENT { RAISE_INDENTATION_ERROR("expected an indented block") }
650660
invalid_comprehension:

Lib/test/test_foo.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

Lib/test/test_syntax.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@
124124
Traceback (most recent call last):
125125
SyntaxError: cannot assign to operator
126126
127+
>>> [a, b[1], c + 1] = [1, 2, 3]
128+
Traceback (most recent call last):
129+
SyntaxError: cannot assign to operator
130+
131+
>>> [a, b.c.d, c + 1] = [1, 2, 3]
132+
Traceback (most recent call last):
133+
SyntaxError: cannot assign to operator
134+
127135
>>> a if 1 else b = 1
128136
Traceback (most recent call last):
129137
SyntaxError: cannot assign to conditional expression

0 commit comments

Comments
 (0)