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

[Pyre] Handle type subscripts when applying annotations. #335

Merged
merged 3 commits into from
Jul 14, 2020

Conversation

MaggieMoss
Copy link
Contributor

Summary

Just as we special case "Type" when applying annotations here: https://github.com/Instagram/LibCST/blob/master/libcst/codemod/visitors/_apply_type_annotations.py#L166
We need to do the same in Subscripts

Test Plan

python -m unittest -v libcst.codemod.visitors.tests.test_apply_type_annotations

@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 Jul 10, 2020
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.

Can you also apply the same change to _create_import_from_annotation by using one matches() instead of isinstance + ==?
https://github.com/Instagram/LibCST/blob/master/libcst/codemod/visitors/_apply_type_annotations.py#L166

Otherwise, LGTM.

Comment on lines 137 to 140
if (
m.matches(node.value, m.Name())
and cst.ensure_type(node.value, cst.Name).value == "Type"
):
Copy link
Contributor

Choose a reason for hiding this comment

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

Use matcher to match the value to be simpler and easier to read.

Suggested change
if (
m.matches(node.value, m.Name())
and cst.ensure_type(node.value, cst.Name).value == "Type"
):
if m.matches(node.value, m.Name(value="type")):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not know you could use this syntax. 😍

@jimmylai jimmylai merged commit 7219efc into Instagram:master Jul 14, 2020
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