-
Notifications
You must be signed in to change notification settings - Fork 13
fixbug: set name for **kwargs #48
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'))) | ||||||||||||
| decorator_list = [] | ||||||||||||
| for decorator in node.decorator_list: | ||||||||||||
| decorator_list.append(self.packPos(decorator, self.visit(decorator))) | ||||||||||||
|
|
@@ -1093,12 +1097,15 @@ def visit_Compare(self, node): | |||||||||||
|
|
||||||||||||
| def visit_keyword(self, node): | ||||||||||||
| # todo 当函数调用使用 **kwargs 展开一个字典时,node.arg 的值为 None | ||||||||||||
| return self.packPos(node, UNode.VariableDeclaration(UNode.SourceLocation(), UNode.Meta(), | ||||||||||||
| keyword = self.packPos(node, UNode.VariableDeclaration(UNode.SourceLocation(), UNode.Meta(), | ||||||||||||
| UNode.Identifier(UNode.SourceLocation(), UNode.Meta(), | ||||||||||||
| node.arg), | ||||||||||||
| self.packPos(node.value, self.visit(node.value)), | ||||||||||||
| False, | ||||||||||||
| UNode.DynamicType(UNode.SourceLocation(), UNode.Meta()))) | ||||||||||||
| if keyword.id.name is None: | ||||||||||||
| keyword.id.name = "kwargs" | ||||||||||||
|
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. Hardcoding the name to "kwargs" for
Suggested change
|
||||||||||||
| return keyword | ||||||||||||
|
|
||||||||||||
| def visit_Starred(self, node): | ||||||||||||
| return self.packPos(node, UNode.DereferenceExpression(UNode.SourceLocation(), UNode.Meta(), | ||||||||||||
|
|
||||||||||||
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.
Keyword expansion loses argument identity
Medium Severity
When
node.argisNone,visit_keywordrewrites every expanded keyword to the fixed namekwargs. This makes distinct**expansions and realkwargs=arguments indistinguishable inCallExpression.arguments, so downstream argument binding can merge or misattribute parameters.