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

Use correct type for AugAssign and AnnAssign target #396

Merged
merged 3 commits into from
Oct 1, 2020

Conversation

cdonovick
Copy link
Contributor

Summary

Closes #391

Changes to libcst/matchers/__init__.py performed by tox -e codegen

Test Plan

I couldn't find any relevant tests to extend but would be happy to write one.

@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 Sep 28, 2020
@jimmylai
Copy link
Contributor

jimmylai commented Sep 30, 2020

This change looks great. It makes LibCST parsing more correctly just like AST.

Can you add invalid test cases to AnnAssignTest and AugAssignTest ?
This is an example.

@data_provider(
(
{
"get_node": (
lambda: cst.AnnAssign(
target=cst.Name("foo"),
annotation=cst.Annotation(cst.Name("str")),
equal=cst.AssignEqual(),
value=None,
)
),
"expected_re": "Must have a value when specifying an AssignEqual.",
},
)
)
def test_invalid(self, **kwargs: Any) -> None:
self.assert_invalid(**kwargs)

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.

Other than missing test cases, LGTM.

@cdonovick
Copy link
Contributor Author

The suggested pattern does not quite work as *Assign._validate doesn't check types just existence/length of arguments. I tried using:

"get_node": (
   # x + 1 : int = y 
   lambda: cst.AnnAssign(...).validate_types_shallow()
)

But this generates a TypeError instead of a CSTValidationError.

I will add a new test methods (test_invalid_types / assert_invalid_types) that will call get_node().validate_types_shallow() similar to the to test_invalid / assert_invalid pattern.

@cdonovick
Copy link
Contributor Author

cdonovick commented Sep 30, 2020

Hmmm not sure what pyre is complaining about. I tried to reproduce locally but I get tons of errors on master so I must have something configured wrong.

Edit:
Possibly my intentional construction of ill-typed nodes? Is there a way to get pyre to skip something?

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.

These should silence the pyre errors (since we're intentionally constructing these types incorrectly)

libcst/_nodes/tests/test_assign.py Show resolved Hide resolved
libcst/_nodes/tests/test_assign.py Show resolved Hide resolved
libcst/_nodes/tests/test_assign.py Show resolved Hide resolved
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.

@cdonovick Looks good now. Thanks for contributing!

@jimmylai jimmylai merged commit 6731aa5 into Instagram:master Oct 1, 2020
@cdonovick cdonovick deleted the issue391 branch October 1, 2020 22:54
@Kronuz Kronuz mentioned this pull request Oct 12, 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.

Incorrect typing of {Ann|Aug}Assign.target
4 participants