-
Notifications
You must be signed in to change notification settings - Fork 17
[FIX] Circular dependency and global assignments imports #448
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
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
Very cool! Thanks for looking into this. Can you add a test for this that would fail before this change and then passes after this change? |
if f"{mod}.{obj}" in helper_functions_fqn: | ||
if ( | ||
f"{mod}.{obj}" in helper_functions_fqn | ||
or dst_context.full_module_name is mod # avoid circular imports |
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.
prefer ==
over is
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.
awesome, thanks
Description
This fixes two issues
circular dependency, which can happen if some object in a module is referenced in the same module and also is imported in the optimized code context like here
imports of the global assignments are not included in the module if they weren't used before adding them, which result in a fatal error when running the tests, fixed just by adding the global assignments before adding the imports, not the opposite
Changes walkthrough 📝
code_extractor.py
Skip same-module imports to prevent circular references
codeflash/code_utils/code_extractor.py
dst_context.full_module_name
equals module