Skip to content

[CG-8871] fix: removing dead code removes code that should stay #355

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

Closed
wants to merge 22 commits into from

Conversation

tkfoss
Copy link
Contributor

@tkfoss tkfoss commented Feb 7, 2025

Motivation

Content

Testing

Please check the following before marking your PR as ready for review

  • I have added tests for my changes
  • I have updated the documentation or added new documentation as needed

@tkfoss tkfoss requested review from codegen-team and a team as code owners February 7, 2025 03:16
@tkfoss tkfoss requested review from caroljung-cg and removed request for a team February 7, 2025 03:16
@CLAassistant
Copy link

CLAassistant commented Feb 7, 2025

CLA assistant check
All committers have signed the CLA.

Copy link

codecov bot commented Feb 11, 2025

Codecov Report

Attention: Patch coverage is 98.21429% with 5 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/codegen/sdk/python/assignment.py 88.57% 4 Missing ⚠️
src/codegen/sdk/python/import_resolution.py 96.87% 1 Missing ⚠️
Additional details and impacted files

Copy link
Contributor

@bagel897 bagel897 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not add a new edge type? That adds a lot of complexity and will likely impact performance. Instead, can we fix the existing edges?

Copy link
Contributor

@bagel897 bagel897 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have the full testing required to make some of these changes with confidence. Can we add a lot of tests for edge cases and maybe split this up?

Returns:
None
"""
if getattr(self.parent, "assignments", None) and len(self.parent.assignments) > 1:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do isinstance here?

@@ -96,3 +99,70 @@ def inline_comment(self) -> PyCommentGroup | None:
"""
# HACK: This is a temporary solution until comments are fixed
return PyCommentGroup.from_symbol_inline_comments(self, self.ts_node.parent)

@remover
def remove(self, delete_formatting: bool = True, priority: int = 0, dedupe: bool = True) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it'll be better to implement _smart_remove rather than overwriting remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to know what Assignment it's being called on and remove dissolves it into Value which does not preserve the distinction, if there is a better idea than override let me know

@reader
@noapidoc
@override
def _resolved_types(self) -> Generator[ResolutionStack[Self], None, None]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the right approach. It will create duplicated edges. For example

def foo():
     ...
def bar():
     ...
from filea import *
foo() # will be a usage of foo and bar

For some context, we regular imports are resolved as follows.

  1. We add the import to valid_import_names
  2. When resolving, we check valid_symbol_names for the name
  3. We call _resolved_types on the import

Since it's impossible to know which symbol you're importing in a wildcard, wildcards follow the following pattern

  1. We check the imported file and get all valid_import_names (this is the same as valid_symbol_names in python) from that file
  2. For each imported symbol, we created a wilcardImport for that name and put it in the valid imports
  3. When resolving, we call _resolved_types on the wildcard import. We create an edge through the import but we point it at the specific imported symbol.

For example, in the above case, we'd call _resolved_types on the wildcard for foo. But it'll create edges from the import to foo and from the call site to foo

Copy link
Contributor Author

@tkfoss tkfoss Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seemed to work as expected, I ve added additional UTs, have I missed anything?

@tkfoss tkfoss closed this Feb 21, 2025
@tkfoss tkfoss deleted the tom-cg-8871-oss-bug-mageai-dead-code branch February 21, 2025 23:05
@tkfoss
Copy link
Contributor Author

tkfoss commented Feb 21, 2025

addressed in #611 and #612

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants