simonpercivall / astunparse

An AST unparser for Python
Other
222 stars 53 forks source link

_Return Function does not check if a return statement has a value in unparse.py #45

Closed NoahGaeta closed 4 years ago

NoahGaeta commented 4 years ago

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 4 years ago

it works as expected on "valid" nodes.

>>> print(astunparse.unparse(ast.parse("def x(): return")))
def x():
    return
NoahGaeta commented 4 years ago

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.