-
Notifications
You must be signed in to change notification settings - Fork 13
Add ReturnStatement for __init__ #49
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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'))) | ||||||||||||||
|
Comment on lines
+339
to
+342
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The nested Additionally, the line that creates the
Suggested change
|
||||||||||||||
| decorator_list = [] | ||||||||||||||
| for decorator in node.decorator_list: | ||||||||||||||
| decorator_list.append(self.packPos(decorator, self.visit(decorator))) | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constructor return added outside classes
Low Severity
visit_FunctionDefappendsreturn selffor any function named__init__, even when it is not a class method. This changes semantics for module-level or nested functions named__init__by introducing a synthetic return value inparser-Python/uast/visitor.py.