Skip to content

Conversation

@vantaboard
Copy link

@vantaboard vantaboard commented Apr 4, 2024

Summary

Creating a RemoveUnusedImports transformer according to the docs does not properly handle the __all__ variable.

Test Plan

I added a test to libcst/metadata/tests/test_scope_provider.py that ensures the imports have references that target the strings in __all__.

@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 4, 2024
Copy link
Contributor

@zsol zsol left a comment

Choose a reason for hiding this comment

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

I wonder what happens for this snippet:

import a, b
__all__: "list[str]" = ["a", "b"]

is_type_hint=False,
)

list(self.scope.assignments[name])[0].record_access(access)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add an entry into self.__deferred_accesses instead, to make sure this Access gets the same treatment as any other.

vantaboard and others added 2 commits April 4, 2024 15:27
@zsol
Copy link
Contributor

zsol commented May 12, 2024

Gotta fix the type errors (looks like Name.__init__ needs updating too) and this is good to go!

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.

3 participants