fix: source match, importProcess and __class__ support#107
fix: source match, importProcess and __class__ support#107CyanM0un wants to merge 1 commit intoantgroup:mainfrom
Conversation
|
You have run out of free Bugbot PR reviews for this billing cycle. This will reset on February 27. To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial. |
Summary of ChangesHello @CyanM0un, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refines the analyzer's capabilities by enhancing how taint sources are identified and how Python imports are resolved. It also introduces support for the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces several improvements to the Python analyzer, including better import resolution, support for __class__, and additional source matching logic. My review focuses on improving code quality and correctness. I've pointed out a potential bug and code duplication in the new source matching logic, and suggested a fix for a typo and non-portable path construction in the import resolver. Overall, the changes are beneficial for the analyzer's capabilities.
| } else if (call.name === tspec.fsig) { | ||
| const args = prepareArgs(res, undefined, tspec) | ||
| for (let i = 0; i < args.length; i++) { | ||
| markTaintSource(args[i], { path: node, kind: tspec.kind }) | ||
| } | ||
| break | ||
| } |
There was a problem hiding this comment.
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.fsig is suspicious. call is a CallExpression node, which typically does not have a name property. This might be a typo for call.callee.name. Please verify the logic and consider refactoring to remove the duplication.
| 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 |
There was a problem hiding this comment.
There's a typo in the variable name mouduleFile. It should be moduleFile.
Additionally, constructing paths using string concatenation with / is not platform-independent and can cause issues on Windows. It's better to use path.join() for all path constructions to ensure portability.
| 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 | |
| const moduleFile = path.join(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(moduleFile))) { | |
| targetPath = moduleFile; | |
| } 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; |
from django.utils import treewhere tree is a python filefrom django.db.models import sqlwhere sql is module dir that contains __init__.py