_Return Function does not check if a return statement has a value in unparse.py
Closed this issue · 2 comments
NoahGaeta commented
It is legal to do this
'''
def f():
return
'''
A fix for the _Return function is this:
'''
def _Return(self, t):
self.fill("return")
if hasattr(t, 'value'):
if t.value:
self.write(" ")
self.dispatch(t.value)
'''
isidentical commented
it works as expected on "valid" nodes.
>>> print(astunparse.unparse(ast.parse("def x(): return")))
def x():
return
NoahGaeta commented
Huh, interesting. I wrote a test for it and I could've swore it failed but I re-tested it and it passed. I thought I hit a corner case with this, sorry about that.