-
Notifications
You must be signed in to change notification settings - Fork 52
CG-10899: file.add_import
#673
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
codegen-bot seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
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.
Some code seems to be copied from other PRs?
tests/unit/codegen/sdk/codebase/session/test_codebase_from_string.py
Outdated
Show resolved
Hide resolved
@writer(commit=False) | ||
def add_import_from_import_string(self, import_string: str) -> None: | ||
"""Adds import to the file from a string representation of an import statement. | ||
def add_import(self, imp: Symbol | str, *, alias: str | None = None, import_type: ImportType = ImportType.UNKNOWN, is_type_import: bool = False) -> Import | None: |
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.
Can we add typing overloads to make sure the user doesn't pass the other parameters if imp is of type str
if any(import_string.strip() in imp.source for imp in self.imports): | ||
return | ||
# Handle Symbol imports | ||
if isinstance(imp, str): |
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.
Can we change the behavior to
- Convert import symbol to string (if it's a symbol)
- Insert the string with the same logic as the previous implementation?
Codecov ReportAll modified and coverable lines are covered by tests ✅ ✅ All tests successful. No failed tests found. Additional details and impacted files |
file.add_import_from_string
andfile.add_symbol_import
has now been consolidated into one methodfile.import
which takes inSymbol | str
either the string import or the Symbol that needs to be imported and will handle the logic