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

[RFC] Analyze attribute access from imports to support dead import clean up better #281

Closed
jimmylai opened this issue Apr 7, 2020 · 0 comments · Fixed by #284
Closed

Comments

@jimmylai
Copy link
Contributor

jimmylai commented Apr 7, 2020

Per @zsol 's request, propose this change. Feedback is welcome.

In this example, the access a.b is recorded in assignment a.b and a.c. So the RemoveUnusedImportsCommand cleans up nothing.

import a.b
import a.c

a.b

It's because we only record the top level name of assignments and accesses.
https://github.com/Instagram/LibCST/blob/master/libcst/metadata/scope_provider.py#L310-L311

For example, when we see an access a.b, a can be imported or a local object.
To provide the dead import clean up support better, we can record the best assignment and access when multiple imports are available in infer_access.

https://github.com/Instagram/LibCST/blob/master/libcst/metadata/scope_provider.py#L786-L800

That means, given an access, we can check all import assignments having the same top level name (a.b and a.c) and only assign the access when it startswith the fully qualified name of the access.

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 a pull request may close this issue.

1 participant