diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2020-11-18 23:44:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-18 23:44:30 (GMT) |
commit | 87c87b5bd6f6a5924b485398f353308410f9d8c1 (patch) | |
tree | 6760033eee437c188edf6b52b71b3469086a7623 /Grammar | |
parent | 36619e1bc49d2e5dbfc86a9f0a54f478fe4a8c2b (diff) | |
download | cpython-87c87b5bd6f6a5924b485398f353308410f9d8c1.zip cpython-87c87b5bd6f6a5924b485398f353308410f9d8c1.tar.gz cpython-87c87b5bd6f6a5924b485398f353308410f9d8c1.tar.bz2 |
[3.9] bpo-42381: Allow walrus in set literals and set comprehensions (GH-23332) (GH-23333)
Currently walruses are not allowerd in set literals and set comprehensions:
>>> {y := 4, 4**2, 3**3}
File "<stdin>", line 1
{y := 4, 4**2, 3**3}
^
SyntaxError: invalid syntax
but they should be allowed as well per PEP 572.
(cherry picked from commit b0aba1fcdc3da952698d99aec2334faa79a8b68c)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Grammar')
-rw-r--r-- | Grammar/python.gram | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram index 257d2f5..ce78397 100644 --- a/Grammar/python.gram +++ b/Grammar/python.gram @@ -301,7 +301,6 @@ block[asdl_seq*] (memo): | simple_stmt | invalid_block -expressions_list[asdl_seq*]: a=','.star_expression+ [','] { a } star_expressions[expr_ty]: | a=star_expression b=(',' c=star_expression { c })+ [','] { _Py_Tuple(CHECK(_PyPegen_seq_insert_in_front(p, a, b)), Load, EXTRA) } @@ -505,9 +504,9 @@ group[expr_ty]: genexp[expr_ty]: | '(' a=named_expression ~ b=for_if_clauses ')' { _Py_GeneratorExp(a, b, EXTRA) } | invalid_comprehension -set[expr_ty]: '{' a=expressions_list '}' { _Py_Set(a, EXTRA) } +set[expr_ty]: '{' a=star_named_expressions '}' { _Py_Set(a, EXTRA) } setcomp[expr_ty]: - | '{' a=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] '}' { |