diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2021-01-31 22:52:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-31 22:52:56 (GMT) |
commit | 835f14ff8eec10b3d96f821a1eb46a986e00c690 (patch) | |
tree | d514cc3cb32ed708ea584edd7c86726f6e581242 /Grammar/python.gram | |
parent | 40901518167c66abc1ebc5b71c5b86d733cfa154 (diff) | |
download | cpython-835f14ff8eec10b3d96f821a1eb46a986e00c690.zip cpython-835f14ff8eec10b3d96f821a1eb46a986e00c690.tar.gz cpython-835f14ff8eec10b3d96f821a1eb46a986e00c690.tar.bz2 |
bpo-43017: Improve error message for unparenthesised tuples in comprehensions (GH24314)
Diffstat (limited to 'Grammar/python.gram')
-rw-r--r-- | Grammar/python.gram | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram index 05ddce5..e72158b 100644 --- a/Grammar/python.gram +++ b/Grammar/python.gram @@ -507,7 +507,7 @@ strings[expr_ty] (memo): a=STRING+ { _PyPegen_concatenate_strings(p, a) } list[expr_ty]: | '[' a=[star_named_expressions] ']' { _Py_List(a, Load, EXTRA) } listcomp[expr_ty]: - | '[' a=named_expression ~ b=for_if_clauses ']' { _Py_ListComp(a, b, EXTRA) } + | '[' a=named_expression b=for_if_clauses ']' { _Py_ListComp(a, b, EXTRA) } | invalid_comprehension tuple[expr_ty]: | '(' a=[y=star_named_expression ',' z=[star_named_expressions] { _PyPegen_seq_insert_in_front(p, y, z) } ] ')' { @@ -516,11 +516,11 @@ group[expr_ty]: | '(' a=(yield_expr | named_expression) ')' { a } | invalid_group genexp[expr_ty]: - | '(' a=named_expression ~ b=for_if_clauses ')' { _Py_GeneratorExp(a, b, EXTRA) } + | '(' a=named_expression b=for_if_clauses ')' { _Py_GeneratorExp(a, b, EXTRA) } | invalid_comprehension set[expr_ty]: '{' a=star_named_expressions '}' { _Py_Set(a, EXTRA) } setcomp[expr_ty]: - | '{' a=named_expression ~ b=for_if_clauses '}' { _Py_SetComp(a, b, EXTRA) } + | '{' a=named_expression b=for_if_clauses '}' { _Py_SetComp(a, b, EXTRA) } | invalid_comprehension dict[expr_ty]: | '{' a=[double_starred_kvpairs] '}' { @@ -692,6 +692,8 @@ invalid_primary: invalid_comprehension: | ('[' | '(' | '{') a=starred_expression for_if_clauses { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "iterable unpacking cannot be used in comprehension") } + | ('[' | '{') a=star_named_expression ',' [star_named_expressions] { + RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "did you forget parentheses around the comprehension target?") } invalid_dict_comprehension: | '{' a='**' bitwise_or for_if_clauses '}' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "dict unpacking cannot be used in dict comprehension") } |