-
Notifications
You must be signed in to change notification settings - Fork 45
Fix: resolve "import as" statements in deconstruct flow #423
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?
Conversation
Summary of ChangesHello @haggit-eliyahu, 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 resolves an issue with how Python 'import ... as ...' statements are processed by the project's code manipulation tools. Previously, these statements were not correctly transformed, especially when converting standard 'import' syntax to 'from ... import ...' for internal and SDK modules. The changes ensure that the 'as' alias is preserved during these transformations, enhancing the robustness of the code refactoring utilities and preventing potential import errors. 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. 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request correctly addresses an issue where import ... as ... statements were not handled properly by the import transformers, causing aliases to be lost. The changes successfully preserve aliases and handle more complex import patterns. The accompanying tests are thorough and cover these new scenarios well.
However, I've identified a critical pre-existing issue in how import statements with multiple names (e.g., import os, sys) are processed. The current logic can lead to silently dropping imports, which could break code. I have provided two review comments with suggestions to address this critical bug, ensuring the transformers are more robust.
688df18 to
4df4e4c
Compare
65efbb2 to
4349b37
Compare
|
/gemini review |
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.
Code Review
This pull request extends the import transformation logic to handle import ... as ... and multi-module import statements. While the added test cases cover many new scenarios, the implementation in both CorePackageImportTransformer and CorePackageInternalImportTransformer contains a critical flaw. The logic incorrectly assumes all modules on a single import line are of the same type and structure, based only on the first module. This can lead to generating invalid import statements when mixed imports are present. I've left detailed comments on the specific transformers with examples of the failing cases. These issues should be addressed, and the test suite should be expanded to include these negative test cases to ensure correctness.
9682092 to
5e2a9d6
Compare
cc7a2ee to
1740fe3
Compare
# Conflicts: # packages/mp/pyproject.toml # packages/mp/uv.lock
1740fe3 to
48b1f10
Compare
|
/gemini review |
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.
Code Review
This pull request effectively addresses the handling of import ... as ... statements and multi-module imports within the code transformation logic. The changes in SdkImportTransformer, CorePackageImportTransformer, and CorePackageInternalImportTransformer are robust and correctly partition and transform various import styles. The addition of leave_SimpleStatementLine to handle import statements at the line level is a smart approach to correctly split core and non-core imports. The new tests are comprehensive and cover a wide range of edge cases, which significantly improves confidence in these changes.
My review includes a couple of suggestions to improve maintainability by refactoring duplicated code and to align docstrings with the project's style guide. Overall, this is a solid improvement to the codebase.
48b1f10 to
2f096d1
Compare
# Conflicts: # packages/mp/pyproject.toml # packages/mp/uv.lock
2f096d1 to
736ded9
Compare
|
/gemini review |
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.
Code Review
This pull request significantly improves the robustness of import statement manipulation by refactoring the CST transformers to handle complex cases like multiple imports on a single line and aliased imports. A new base class BaseCoreImportTransformer is introduced to abstract common logic, which is a great design choice. The changes also fix a bug where only the first module in an import statement was being processed. Additionally, comprehensive unit tests have been added to cover these new scenarios, ensuring the changes are well-tested. The code quality is high. I have one suggestion to further improve maintainability by using Python's abc module for abstract base classes.
cd69491 to
e764dcb
Compare
Description
handle statements of the format "import * as *".
some cases has to change it to "from * import * as *" due to using relative path.
Checklist:
Please ensure you have completed the following items before submitting your PR.
This helps us review your contribution faster and more efficiently.
General Checks:
Open-Source Specific Checks:
For Google Team Members and Reviewers Only:
Screenshots (If Applicable)
If your changes involve UI or visual elements, please include screenshots or GIFs here.
Ensure any sensitive data is redacted or generalized.
Further Comments / Questions
Any additional comments, questions, or areas where you'd like specific feedback.