diff --git a/parser-Python/uast/visitor.py b/parser-Python/uast/visitor.py index 64bcf88..ce70ae5 100644 --- a/parser-Python/uast/visitor.py +++ b/parser-Python/uast/visitor.py @@ -336,6 +336,10 @@ def visit_FunctionDef(self, node): if node.name == '__init__': function_def._meta.isConstructor = True # function_def.body.body.append(UNode.ReturnStatement(UNode.SourceLocation(), UNode.Meta(), UNode.Identifier(UNode.SourceLocation(), UNode.Meta(), 'self'))) + if len(body) > 0: + last_stmt = body[-1] + if not isinstance(last_stmt, UNode.ReturnStatement): + function_def.body.body.append(UNode.ReturnStatement(UNode.SourceLocation(), UNode.Meta(), UNode.Identifier(UNode.SourceLocation(), UNode.Meta(), 'self'))) decorator_list = [] for decorator in node.decorator_list: decorator_list.append(self.packPos(decorator, self.visit(decorator)))