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

Return more specific QNames for assignments #477

Merged
merged 3 commits into from
Apr 19, 2021

Conversation

zsol
Copy link
Member

@zsol zsol commented Apr 15, 2021

Summary

When scope.get_qualified_names_for() is called with a node that's an Assignment, return the qualified name for that node instead of all the assignments for the same name.

For example:

if False:
  def f(): pass  # {"f"}
else:
  from a import f  # {"a.f"}

f()  # {"f", "a.f"}

Before this PR, all three nodes had the same set of qnames returned ({"f", "a.f"}).

Test Plan

Will add tests before merging.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 15, 2021
@zsol zsol requested a review from jimmylai April 15, 2021 11:14
Copy link
Contributor

@jimmylai jimmylai left a comment

Choose a reason for hiding this comment

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

I like this change which provides more accurate and useful names.
Please also add test cases and the document.

@zsol
Copy link
Member Author

zsol commented Apr 19, 2021

While working on this I discovered that QualifiedNameProvider didn't provide names for import statements, so I added this in the commits above. This caused a completely unrelated RenameCommand to break because it assumes Name nodes inside imports don't have a qualified name (for example here).

I'll try and fix the codemod, but may decide it's more trouble than worth and just leave the original behavior for imports:

if False:
  def f(): pass  # {}
else:
  from a import f  # {"a.f"}

f()  # {"f", "a.f"}

@zsol zsol merged commit 3b21fa9 into Instagram:master Apr 19, 2021
zsol added a commit to zsol/LibCST that referenced this pull request Apr 19, 2021
zsol added a commit to zsol/LibCST that referenced this pull request Aug 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants