@@ -502,11 +502,13 @@ dict[expr_ty]:
502
502
| '{' a=[kvpairs] '}' { _Py_Dict(CHECK(_PyPegen_get_keys(p, a)),
503
503
CHECK(_PyPegen_get_values(p, a)), EXTRA) }
504
504
dictcomp[expr_ty]:
505
- | '{' a=kvpair b=for_if_clauses '}' { _Py_DictComp(a->key, a->value, b, EXTRA) }
505
+ | '{' a=simple_kvpair b=for_if_clauses '}' { _Py_DictComp(a->key, a->value, b, EXTRA) }
506
+ | invalid_dict_comprehension
506
507
kvpairs[asdl_seq*]: a=','.kvpair+ [','] { a }
507
508
kvpair[KeyValuePair*]:
508
509
| '**' a=bitwise_or { _PyPegen_key_value_pair(p, NULL, a) }
509
- | a=expression ':' b=expression { _PyPegen_key_value_pair(p, a, b) }
510
+ | simple_kvpair
511
+ simple_kvpair[KeyValuePair*]: a=expression ':' b=expression { _PyPegen_key_value_pair(p, a, b) }
510
512
for_if_clauses[asdl_seq*]:
511
513
| for_if_clause+
512
514
for_if_clause[comprehension_ty]:
@@ -657,6 +659,9 @@ invalid_block:
657
659
invalid_comprehension:
658
660
| ('[' | '(' | '{') a=starred_expression for_if_clauses {
659
661
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "iterable unpacking cannot be used in comprehension") }
662
+ invalid_dict_comprehension:
663
+ | '{' a='**' bitwise_or for_if_clauses '}' {
664
+ RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "dict unpacking cannot be used in dict comprehension") }
660
665
invalid_parameters:
661
666
| param_no_default* (slash_with_default | param_with_default+) param_no_default {
662
667
RAISE_SYNTAX_ERROR("non-default argument follows default argument") }
0 commit comments