-
Notifications
You must be signed in to change notification settings - Fork 22
fix(python): only create subscope for FunctionDefinition #103
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
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 |
|---|---|---|
|
|
@@ -744,7 +744,11 @@ class PythonAnalyzer extends (Analyzer as any) { | |
| } else { | ||
| scopeName = `<block_${Uuid.v4()}>` | ||
| } | ||
| const block_scope = Scope.createSubScope(scopeName, scope, 'scope') | ||
| let block_scope = scope | ||
| if (node.parent?.type === 'FunctionDefinition') { | ||
| // 只对函数体内的块语句创建子作用域,python的其他块语句不创建子作用域 | ||
| block_scope = Scope.createSubScope(scopeName, scope, 'scope') | ||
| } | ||
|
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. List comprehensions may lose scope isolation in Python 3Medium Severity The change only creates subscopes for |
||
| node.body | ||
| .filter((n: any) => needCompileFirst(n.type)) | ||
| .forEach((s: any) => this.processInstruction(block_scope, s, state)) | ||
|
|
||
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.
This logic can be made more concise by using a ternary operator. This also allows
block_scopeto be declared withconst, which is generally preferred for variables that are not reassigned.