Skip to content

Commit

Permalink
python#111488: Changed error message in case of no 'in' keyword after…
Browse files Browse the repository at this point in the history
… 'for' in list

comprehensions
  • Loading branch information
grigoriev-semyon committed Jan 2, 2024
1 parent acf4cf5 commit 7b74e41
Show file tree
Hide file tree
Showing 5 changed files with 1,718 additions and 1,591 deletions.
2 changes: 2 additions & 0 deletions Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,8 @@ 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' {
RAISE_SYNTAX_ERROR("'in' expected after for-loop variables") }
| invalid_for_target

listcomp[expr_ty]:
Expand Down
14 changes: 14 additions & 0 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,20 @@
Traceback (most recent call last):
SyntaxError: invalid syntax
Comprehensions without 'in' keyword:
>>> [x for x if range(1)]
Traceback (most recent call last):
SyntaxError: 'in' expected after for-loop variables
>>> tuple(x for x if range(1))
Traceback (most recent call last):
SyntaxError: 'in' expected after for-loop variables
>>> [x for x() in a]
Traceback (most recent call last):
SyntaxError: cannot assign to function call
Comprehensions creating tuples without parentheses
should produce a specialized error message:
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ Eddy De Greef
Duane Griffin
Grant Griffin
Andrea Griffini
Semyon Grigoryev
Duncan Grisby
Olivier Grisel
Fabian Groffen
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Changed error message in case of no 'in' keyword after 'for' in list
comprehensions
Loading

0 comments on commit 7b74e41

Please sign in to comment.