]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-38870: Throw ValueError on invalid yield from usage (GH-17798)
authorBatuhan Taşkaya <47358913+isidentical@users.noreply.github.com>
Thu, 2 Jan 2020 18:20:04 +0000 (21:20 +0300)
committerPablo Galindo <Pablogsal@gmail.com>
Thu, 2 Jan 2020 18:20:04 +0000 (18:20 +0000)
Lib/ast.py
Lib/test/test_unparse.py

index 62f6e075a09fdf2a3f23927b16756f87f1d33df7..ece8b139e460eeb0ea784e13ae16fa000953af94 100644 (file)
@@ -735,10 +735,10 @@ class _Unparser(NodeVisitor):
 
     def visit_YieldFrom(self, node):
         with self.delimit("(", ")"):
-            self.write("yield from")
-            if node.value:
-                self.write(" ")
-                self.traverse(node.value)
+            self.write("yield from ")
+            if not node.value:
+                raise ValueError("Node can't be used without a value attribute.")
+            self.traverse(node.value)
 
     def visit_Raise(self, node):
         self.fill("raise")
index 49767dbac16d11ffe42f31cc896e465ff950a70b..e8b0d4b06f9e97bc815b896f8084b60a28deef31 100644 (file)
@@ -278,6 +278,8 @@ class UnparseTestCase(ASTTestCase):
     def test_invalid_set(self):
         self.check_invalid(ast.Set(elts=[]))
 
+    def test_invalid_yield_from(self):
+        self.check_invalid(ast.YieldFrom(value=None))
 
 class DirectoryTestCase(ASTTestCase):
     """Test roundtrip behaviour on all files in Lib and Lib/test."""