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

fix: __all__ references are not ignored #1129

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

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
Member

@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"]

libcst/metadata/scope_provider.py Outdated Show resolved Hide resolved
libcst/metadata/scope_provider.py Outdated Show resolved Hide resolved
is_type_hint=False,
)

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

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
Member

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