Skip to content
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

refactor: prefix trimming as a node transformer #113

Conversation

Eric-Mendes
Copy link

@Eric-Mendes Eric-Mendes commented Nov 16, 2022

Overview

Implemented the change proposed in issue #81.

Details

Couldn't figure out a nice way of implementing automatic detection of used libraries and its aliases as discussed in #88, so in this implementation the user needs to pass them in a set[str] called prefixes.

References

#81 #87

Blocked by

NA

@Eric-Mendes Eric-Mendes requested a review from odashi as a code owner November 16, 2022 00:41
Eric-Mendes and others added 6 commits November 15, 2022 22:25
Co-authored-by: Yusuke Oda <yusuke.oda@predicate.jp>
Co-authored-by: Yusuke Oda <yusuke.oda@predicate.jp>
Co-authored-by: Yusuke Oda <yusuke.oda@predicate.jp>
Co-authored-by: Yusuke Oda <yusuke.oda@predicate.jp>
Co-authored-by: Yusuke Oda <yusuke.oda@predicate.jp>
Co-authored-by: Yusuke Oda <yusuke.oda@predicate.jp>
@odashi odashi added the feature label Nov 16, 2022
@odashi odashi added this to the v0.3 milestone Nov 16, 2022
@odashi
Copy link
Collaborator

odashi commented Nov 16, 2022

@Eric-Mendes If you finished refactoring, please push the re-request button (the arrow circle) on the right pane.

@Eric-Mendes Eric-Mendes requested a review from odashi November 16, 2022 05:05
"""
self._prefixes = prefixes

def visit_Call(self, node: ast.Call) -> ast.Call:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think visit_Call is no longer necessary, as you implemented visit_Attribute instead, which can process every Attribute node in the tree.

Copy link
Author

Choose a reason for hiding this comment

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

Without it tests fail. Not sure why

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you provide the example outputs you observed?

while isinstance(node_value, ast.Attribute):
node_value = node_value.value

# if outermost prefix matches any given prefix, loose
Copy link
Collaborator

@odashi odashi Nov 16, 2022

Choose a reason for hiding this comment

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

I think this policy is not safe as the dropped subtree may involve the stuff that the users didn't expect. It would be better to drop only the leftmost prefix, and provide a way to specify longer chains to drop: "foo.bar" (but this may be somewhat beyond the scope of this pull request).

@odashi
Copy link
Collaborator

odashi commented Nov 16, 2022

@Eric-Mendes Hi, it looks all failed tests belong to function_codegen_test.py. These tests only invoke FunctionCodegen without any preprocessing.

Since this pull request removed the trimming behavior from FunctionCodegen, the codegen no longer recognize any prefixes, resulting in some test failures. You need to fix the input text of test cases to have trimmed identifiers, e.g., math.prod -> prod

@odashi
Copy link
Collaborator

odashi commented Nov 23, 2022

@Eric-Mendes Hi, it looks the test is still failing, and there's some conflicts against main. I'd appreciate it if you could resolve these issues.

@odashi
Copy link
Collaborator

odashi commented Nov 27, 2022

Closes this pull request due to more than 1 week inactivity.

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

Successfully merging this pull request may close these issues.

2 participants