Skip to content

Commit

Permalink
python#111488 fix cannot assign to expr
Browse files Browse the repository at this point in the history
  • Loading branch information
grigoriev-semyon committed Jan 3, 2024
1 parent 7c5b1f1 commit abb1d3b
Show file tree
Hide file tree
Showing 3 changed files with 350 additions and 249 deletions.
2 changes: 1 addition & 1 deletion Grammar/python.gram
Expand Up @@ -968,7 +968,7 @@ for_if_clause[comprehension_ty]:
CHECK_VERSION(comprehension_ty, 6, "Async comprehensions are", _PyAST_comprehension(a, b, c, 1, p->arena)) }
| 'for' a=star_targets 'in' ~ b=disjunction c[asdl_expr_seq*]=('if' z=disjunction { z })* {
_PyAST_comprehension(a, b, c, 0, p->arena) }
| 'async'? 'for' a=star_targets+ !'in' {
| 'async'? 'for' (bitwise_or (',' bitwise_or)* [',']) !'in' {
RAISE_SYNTAX_ERROR("'in' expected after for-loop variables") }
| invalid_for_target

Expand Down
16 changes: 16 additions & 0 deletions Lib/test/test_syntax.py
Expand Up @@ -273,6 +273,22 @@
Traceback (most recent call last):
SyntaxError: cannot assign to function call
>>> [x for a, b, (c + 1, d()) in y]
Traceback (most recent call last):
SyntaxError: cannot assign to expression
>>> [x for a, b, (c + 1, d()) if y]
Traceback (most recent call last):
SyntaxError: 'in' expected after for-loop variables
>>> [x for x+1 in y]
Traceback (most recent call last):
SyntaxError: cannot assign to expression
>>> [x for x+1, x() in y]
Traceback (most recent call last):
SyntaxError: cannot assign to expression
Comprehensions creating tuples without parentheses
should produce a specialized error message:
Expand Down

0 comments on commit abb1d3b

Please sign in to comment.