-
Notifications
You must be signed in to change notification settings - Fork 22
fix: source match, importProcess and __class__ support #107
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 | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -475,9 +475,15 @@ class PythonAnalyzer extends (Analyzer as any) { | |||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| let targetPath = normalizedPath | ||||||||||||||||||||||||||||||||||||||||||||
| if (!targetPath.endsWith('.py')) { | ||||||||||||||||||||||||||||||||||||||||||||
| const mouduleFile = `${targetPath}/${modulePath}.py` | ||||||||||||||||||||||||||||||||||||||||||||
| const moduleInitFile = path.join(`${targetPath}/${modulePath}`, '__init__.py') | ||||||||||||||||||||||||||||||||||||||||||||
| // 可能是包目录,检查是否有 __init__.py | ||||||||||||||||||||||||||||||||||||||||||||
| const initFile = path.join(targetPath, '__init__.py') | ||||||||||||||||||||||||||||||||||||||||||||
| if (this.fileList.some((f: string) => path.normalize(f) === path.normalize(initFile))) { | ||||||||||||||||||||||||||||||||||||||||||||
| if (this.fileList.some((f: string) => path.normalize(f) === path.normalize(mouduleFile))) { | ||||||||||||||||||||||||||||||||||||||||||||
| targetPath = mouduleFile | ||||||||||||||||||||||||||||||||||||||||||||
| } else if (this.fileList.some((f: string) => path.normalize(f) === path.normalize(moduleInitFile))) { | ||||||||||||||||||||||||||||||||||||||||||||
| targetPath = moduleInitFile | ||||||||||||||||||||||||||||||||||||||||||||
| } else if (this.fileList.some((f: string) => path.normalize(f) === path.normalize(initFile))) { | ||||||||||||||||||||||||||||||||||||||||||||
| targetPath = initFile | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+478
to
487
Contributor
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. There's a typo in the variable name Additionally, constructing paths using string concatenation with
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||
| // 尝试添加 .py 扩展名 | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -557,7 +563,7 @@ class PythonAnalyzer extends (Analyzer as any) { | |||||||||||||||||||||||||||||||||||||||||||
| } else if (prop.type !== 'Identifier' && prop.type !== 'Literal') { | ||||||||||||||||||||||||||||||||||||||||||||
| resolved_prop = this.processInstruction(scope, prop, state) | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| if (prop.type === 'Identifier' && prop.name === '__init__' && prop.parent?.parent?.type === 'CallExpression') { | ||||||||||||||||||||||||||||||||||||||||||||
| if (prop.type === 'Identifier' && (prop.name === '__init__' || prop.name === '__class__') && prop.parent?.parent?.type === 'CallExpression') { | ||||||||||||||||||||||||||||||||||||||||||||
| resolved_prop.name = '_CTOR_' | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| if (!resolved_prop) return defscope | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
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.
The logic in this block is identical to the one in lines 131-135. This code duplication should be avoided.
Additionally, the condition
call.name === tspec.fsigis suspicious.callis aCallExpressionnode, which typically does not have anameproperty. This might be a typo forcall.callee.name. Please verify the logic and consider refactoring to remove the duplication.