Skip to content

Commit 768d739

Browse files
authored
bpo-38641: Add lib2to3 support for starred expressions in return/yield statements (GH-16994)
1 parent 0b0d29f commit 768d739

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

Lib/lib2to3/Grammar.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pass_stmt: 'pass'
4949
flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt
5050
break_stmt: 'break'
5151
continue_stmt: 'continue'
52-
return_stmt: 'return' [testlist]
52+
return_stmt: 'return' [testlist_star_expr]
5353
yield_stmt: yield_expr
5454
raise_stmt: 'raise' [test ['from' test | ',' test [',' test]]]
5555
import_stmt: import_name | import_from
@@ -151,4 +151,4 @@ testlist1: test (',' test)*
151151
encoding_decl: NAME
152152

153153
yield_expr: 'yield' [yield_arg]
154-
yield_arg: 'from' test | testlist
154+
yield_arg: 'from' test | testlist_star_expr

Lib/lib2to3/tests/data/py3_test_grammar.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,15 +473,27 @@ def test_inner(extra_burning_oil = 1, count=0):
473473
test_inner()
474474

475475
def testReturn(self):
476-
# 'return' [testlist]
476+
# 'return' [testlist_star_expr]
477477
def g1(): return
478478
def g2(): return 1
479+
return_list = [2, 3]
480+
def g3(): return 1, *return_list
479481
g1()
480482
x = g2()
483+
x3 = g3()
481484
check_syntax_error(self, "class foo:return 1")
482485

483486
def testYield(self):
487+
# 'yield' [yield_arg]
488+
def g1(): yield 1
489+
yield_list = [2, 3]
490+
def g2(): yield 1, *yield_list
491+
def g3(): yield from iter(yield_list)
492+
x1 = g1()
493+
x2 = g2()
494+
x3 = g3()
484495
check_syntax_error(self, "class foo:yield 1")
496+
check_syntax_error(self, "def g4(): yield from *a")
485497

486498
def testRaise(self):
487499
# 'raise' test [',' test]

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,5 +1914,6 @@ Jelle Zijlstra
19141914
Gennadiy Zlobin
19151915
Doug Zongker
19161916
Peter Åstrand
1917+
Vlad Emelianov
19171918

19181919
(Entries should be added in rough alphabetical order by last names)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Added starred expressions support to ``return`` and ``yield`` statements for
2+
``lib2to3``. Patch by Vlad Emelianov.

0 commit comments

Comments
 (0)