bpo-38641: Add lib2to3 support for starred expressions in return/yield statements (GH-16994)

This commit is contained in:
Vlad Emelianov 2020-03-01 20:59:26 +01:00 committed by GitHub
parent 0b0d29fce5
commit 768d739c1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 3 deletions

View File

@ -49,7 +49,7 @@ pass_stmt: 'pass'
flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt
break_stmt: 'break' break_stmt: 'break'
continue_stmt: 'continue' continue_stmt: 'continue'
return_stmt: 'return' [testlist] return_stmt: 'return' [testlist_star_expr]
yield_stmt: yield_expr yield_stmt: yield_expr
raise_stmt: 'raise' [test ['from' test | ',' test [',' test]]] raise_stmt: 'raise' [test ['from' test | ',' test [',' test]]]
import_stmt: import_name | import_from import_stmt: import_name | import_from
@ -151,4 +151,4 @@ testlist1: test (',' test)*
encoding_decl: NAME encoding_decl: NAME
yield_expr: 'yield' [yield_arg] yield_expr: 'yield' [yield_arg]
yield_arg: 'from' test | testlist yield_arg: 'from' test | testlist_star_expr

View File

@ -473,15 +473,27 @@ class GrammarTests(unittest.TestCase):
test_inner() test_inner()
def testReturn(self): def testReturn(self):
# 'return' [testlist] # 'return' [testlist_star_expr]
def g1(): return def g1(): return
def g2(): return 1 def g2(): return 1
return_list = [2, 3]
def g3(): return 1, *return_list
g1() g1()
x = g2() x = g2()
x3 = g3()
check_syntax_error(self, "class foo:return 1") check_syntax_error(self, "class foo:return 1")
def testYield(self): def testYield(self):
# 'yield' [yield_arg]
def g1(): yield 1
yield_list = [2, 3]
def g2(): yield 1, *yield_list
def g3(): yield from iter(yield_list)
x1 = g1()
x2 = g2()
x3 = g3()
check_syntax_error(self, "class foo:yield 1") check_syntax_error(self, "class foo:yield 1")
check_syntax_error(self, "def g4(): yield from *a")
def testRaise(self): def testRaise(self):
# 'raise' test [',' test] # 'raise' test [',' test]

View File

@ -1914,5 +1914,6 @@ Jelle Zijlstra
Gennadiy Zlobin Gennadiy Zlobin
Doug Zongker Doug Zongker
Peter Åstrand Peter Åstrand
Vlad Emelianov
(Entries should be added in rough alphabetical order by last names) (Entries should be added in rough alphabetical order by last names)

View File

@ -0,0 +1,2 @@
Added starred expressions support to ``return`` and ``yield`` statements for
``lib2to3``. Patch by Vlad Emelianov.