From 00109c9bd3b5c14e8281addc79a79fda3c310806 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 10 Apr 2014 00:23:18 -0400 Subject: [PATCH] teach 2to3 about 'yield from' --- Lib/lib2to3/Grammar.txt | 3 ++- Lib/lib2to3/tests/test_parser.py | 7 +++++++ Misc/NEWS | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Lib/lib2to3/Grammar.txt b/Lib/lib2to3/Grammar.txt index bc084e9790..e667bcde69 100644 --- a/Lib/lib2to3/Grammar.txt +++ b/Lib/lib2to3/Grammar.txt @@ -155,4 +155,5 @@ testlist1: test (',' test)* # not used in grammar, but may appear in "node" passed from Parser to Compiler encoding_decl: NAME -yield_expr: 'yield' [testlist] +yield_expr: 'yield' [yield_arg] +yield_arg: 'from' test | testlist diff --git a/Lib/lib2to3/tests/test_parser.py b/Lib/lib2to3/tests/test_parser.py index 2e5af45399..9c5463a7c0 100644 --- a/Lib/lib2to3/tests/test_parser.py +++ b/Lib/lib2to3/tests/test_parser.py @@ -50,6 +50,13 @@ class TestMatrixMultiplication(GrammarTest): self.validate("a @= b") +class TestYieldFrom(GrammarTest): + def test_matrix_multiplication_operator(self): + self.validate("yield from x") + self.validate("(yield from x) + y") + self.invalid_syntax("yield from") + + class TestRaiseChanges(GrammarTest): def test_2x_style_1(self): self.validate("raise") diff --git a/Misc/NEWS b/Misc/NEWS index fb06c015ba..7756e89c3d 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -266,6 +266,8 @@ Library Tools/Demos ----------- +- Add support for ``yield from`` to 2to3. + - Add support for the PEP 465 matrix multiplication operator to 2to3. - Issue #19936: Added executable bits or shebang lines to Python scripts which -- 2.50.1