Skip to content

bpo-38870: Throw ValueError on invalid yield from usage #17798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Lib/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,10 +735,10 @@ def visit_Yield(self, node):

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")
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_unparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ def test_invalid_fstring_conversion(self):
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."""
Expand Down