diff options
author | Batuhan Taşkaya <47358913+isidentical@users.noreply.github.com> | 2020-01-02 18:20:04 (GMT) |
---|---|---|
committer | Pablo Galindo <Pablogsal@gmail.com> | 2020-01-02 18:20:04 (GMT) |
commit | 7b35bef9787cd80ed1e12124f759b4be03c849db (patch) | |
tree | 6b9acbbb48a86fc49da74afc2c9a97f31373f6bc /Lib | |
parent | 78018bb1621e5ecb61cba6e664d14ff789d2874c (diff) | |
download | cpython-7b35bef9787cd80ed1e12124f759b4be03c849db.zip cpython-7b35bef9787cd80ed1e12124f759b4be03c849db.tar.gz cpython-7b35bef9787cd80ed1e12124f759b4be03c849db.tar.bz2 |
bpo-38870: Throw ValueError on invalid yield from usage (GH-17798)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/ast.py | 8 | ||||
-rw-r--r-- | Lib/test/test_unparse.py | 2 |
2 files changed, 6 insertions, 4 deletions
@@ -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") diff --git a/Lib/test/test_unparse.py b/Lib/test/test_unparse.py index 49767db..e8b0d4b 100644 --- a/Lib/test/test_unparse.py +++ b/Lib/test/test_unparse.py @@ -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.""" |