bpo-38870: Throw ValueError on invalid yield from usage (GH-17798)

This commit is contained in:
Batuhan Taşkaya 2020-01-02 21:20:04 +03:00 committed by Pablo Galindo
parent 78018bb162
commit 7b35bef978
2 changed files with 6 additions and 4 deletions

View 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")

View 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."""