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

Vlad Emelianov webhook-mailer at python.org
Sun Mar 1 14:59:35 EST 2020


https://github.com/python/cpython/commit/768d739c1cd8c1d41902229581811a9b86bcc76e
commit: 768d739c1cd8c1d41902229581811a9b86bcc76e
branch: master
author: Vlad Emelianov <volshebnyi at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020-03-01T19:59:26Z
summary:

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

files:
A Misc/NEWS.d/next/Library/2019-10-30-15-31-09.bpo-38641.HrTL9k.rst
M Lib/lib2to3/Grammar.txt
M Lib/lib2to3/tests/data/py3_test_grammar.py
M Misc/ACKS

diff --git a/Lib/lib2to3/Grammar.txt b/Lib/lib2to3/Grammar.txt
index 68b73868b5828..51f58209f036f 100644
--- a/Lib/lib2to3/Grammar.txt
+++ b/Lib/lib2to3/Grammar.txt
@@ -49,7 +49,7 @@ pass_stmt: 'pass'
 flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt
 break_stmt: 'break'
 continue_stmt: 'continue'
-return_stmt: 'return' [testlist]
+return_stmt: 'return' [testlist_star_expr]
 yield_stmt: yield_expr
 raise_stmt: 'raise' [test ['from' test | ',' test [',' test]]]
 import_stmt: import_name | import_from
@@ -151,4 +151,4 @@ testlist1: test (',' test)*
 encoding_decl: NAME
 
 yield_expr: 'yield' [yield_arg]
-yield_arg: 'from' test | testlist
+yield_arg: 'from' test | testlist_star_expr
diff --git a/Lib/lib2to3/tests/data/py3_test_grammar.py b/Lib/lib2to3/tests/data/py3_test_grammar.py
index e0b682837e1d8..d06223207e1ec 100644
--- a/Lib/lib2to3/tests/data/py3_test_grammar.py
+++ b/Lib/lib2to3/tests/data/py3_test_grammar.py
@@ -473,15 +473,27 @@ def test_inner(extra_burning_oil = 1, count=0):
         test_inner()
 
     def testReturn(self):
-        # 'return' [testlist]
+        # 'return' [testlist_star_expr]
         def g1(): return
         def g2(): return 1
+        return_list = [2, 3]
+        def g3(): return 1, *return_list
         g1()
         x = g2()
+        x3 = g3()
         check_syntax_error(self, "class foo:return 1")
 
     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, "def g4(): yield from *a")
 
     def testRaise(self):
         # 'raise' test [',' test]
diff --git a/Misc/ACKS b/Misc/ACKS
index 1b5febb1d19d8..b36e2de4c2ba5 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1914,5 +1914,6 @@ Jelle Zijlstra
 Gennadiy Zlobin
 Doug Zongker
 Peter Åstrand
+Vlad Emelianov
 
 (Entries should be added in rough alphabetical order by last names)
diff --git a/Misc/NEWS.d/next/Library/2019-10-30-15-31-09.bpo-38641.HrTL9k.rst b/Misc/NEWS.d/next/Library/2019-10-30-15-31-09.bpo-38641.HrTL9k.rst
new file mode 100644
index 0000000000000..c547712d81367
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-10-30-15-31-09.bpo-38641.HrTL9k.rst
@@ -0,0 +1,2 @@
+Added starred expressions support to ``return`` and ``yield`` statements for
+``lib2to3``. Patch by Vlad Emelianov.



More information about the Python-checkins mailing list