diff options
author | Batuhan Taskaya <isidentical@gmail.com> | 2020-05-21 22:39:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-21 22:39:56 (GMT) |
commit | b8a65ec1d3d4660d0ee38a9765d98f5cdcabdef5 (patch) | |
tree | d34d214c00702aa047f96b35e91613a1fe892df5 /Grammar | |
parent | 72e0aa2fd2b9c6da2caa5a9ef54f6495fc2890b0 (diff) | |
download | cpython-b8a65ec1d3d4660d0ee38a9765d98f5cdcabdef5.zip cpython-b8a65ec1d3d4660d0ee38a9765d98f5cdcabdef5.tar.gz cpython-b8a65ec1d3d4660d0ee38a9765d98f5cdcabdef5.tar.bz2 |
bpo-40715: Reject dict unpacking on dict comprehensions (GH-20292)
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
Diffstat (limited to 'Grammar')
-rw-r--r-- | Grammar/python.gram | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram index 9bf2697..a771abf 100644 --- a/Grammar/python.gram +++ b/Grammar/python.gram @@ -499,14 +499,16 @@ setcomp[expr_ty]: | '{' a=expression b=for_if_clauses '}' { _Py_SetComp(a, b, EXTRA) } | invalid_comprehension dict[expr_ty]: - | '{' a=[kvpairs] '}' { _Py_Dict(CHECK(_PyPegen_get_keys(p, a)), - CHECK(_PyPegen_get_values(p, a)), EXTRA) } + | '{' a=[double_starred_kvpairs] '}' { + _Py_Dict(CHECK(_PyPegen_get_keys(p, a)), CHECK(_PyPegen_get_values(p, a)), EXTRA) } dictcomp[expr_ty]: | '{' a=kvpair b=for_if_clauses '}' { _Py_DictComp(a->key, a->value, b, EXTRA) } -kvpairs[asdl_seq*]: a=','.kvpair+ [','] { a } -kvpair[KeyValuePair*]: + | invalid_dict_comprehension +double_starred_kvpairs[asdl_seq*]: a=','.double_starred_kvpair+ [','] { a } +double_starred_kvpair[KeyValuePair*]: | '**' a=bitwise_or { _PyPegen_key_value_pair(p, NULL, a) } - | a=expression ':' b=expression { _PyPegen_key_value_pair(p, a, b) } + | kvpair +kvpair[KeyValuePair*]: a=expression ':' b=expression { _PyPegen_key_value_pair(p, a, b) } for_if_clauses[asdl_seq*]: | for_if_clause+ for_if_clause[comprehension_ty]: @@ -657,6 +659,9 @@ invalid_block: invalid_comprehension: | ('[' | '(' | '{') a=starred_expression for_if_clauses { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "iterable unpacking cannot be used in comprehension") } +invalid_dict_comprehension: + | '{' a='**' bitwise_or for_if_clauses '}' { + RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "dict unpacking cannot be used in dict comprehension") } invalid_parameters: | param_no_default* (slash_with_default | param_with_default+) param_no_default { RAISE_SYNTAX_ERROR("non-default argument follows default argument") } |