Skip to content

Commit 53ffbdd

Browse files
dacutjChapman
authored andcommitted
Fix return statements to allow unpacking without parenthesis.
1 parent 10a428b commit 53ffbdd

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

Grammar/Grammar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pass_stmt: 'pass'
5050
flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt
5151
break_stmt: 'break'
5252
continue_stmt: 'continue'
53-
return_stmt: 'return' [testlist]
53+
return_stmt: 'return' [testlist_star_expr]
5454
yield_stmt: yield_expr
5555
raise_stmt: 'raise' [test ['from' test]]
5656
import_stmt: import_name | import_from

Lib/test/test_grammar.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,11 +824,17 @@ def test_inner(extra_burning_oil = 1, count=0):
824824
test_inner()
825825

826826
def test_return(self):
827-
# 'return' [testlist]
827+
# 'return' [testlist_star_expr]
828828
def g1(): return
829829
def g2(): return 1
830+
def g3():
831+
z = [2, 3]
832+
return 1, *z
833+
830834
g1()
831835
x = g2()
836+
y = g3()
837+
self.assertEqual(y, (1, 2, 3), "unparenthesized star expr return")
832838
check_syntax_error(self, "class foo:return 1")
833839

834840
def test_break_in_finally(self):

Python/graminit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ static arc arcs_25_0[1] = {
613613
{75, 1},
614614
};
615615
static arc arcs_25_1[2] = {
616-
{9, 2},
616+
{47, 2},
617617
{0, 1},
618618
};
619619
static arc arcs_25_2[1] = {

0 commit comments

Comments
 (0)