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

Support PEP 604 in ApplyTypeAnnotationsVisitor #868

Merged
merged 7 commits into from
Apr 21, 2023

Conversation

hauntsaninja
Copy link
Contributor

No description provided.

@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 Feb 18, 2023
@codecov-commenter
Copy link

codecov-commenter commented Feb 18, 2023

Codecov Report

Patch coverage: 96.42% and project coverage change: +0.13 🎉

Comparison is base (8aebbb6) 94.79% compared to head (dada184) 94.93%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #868      +/-   ##
==========================================
+ Coverage   94.79%   94.93%   +0.13%     
==========================================
  Files         249      254       +5     
  Lines       25831    25923      +92     
==========================================
+ Hits        24487    24609     +122     
+ Misses       1344     1314      -30     
Impacted Files Coverage Δ
libcst/codemod/visitors/_apply_type_annotations.py 97.15% <96.00%> (+1.72%) ⬆️
...emod/visitors/tests/test_apply_type_annotations.py 100.00% <100.00%> (ø)

... and 42 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@hauntsaninja
Copy link
Contributor Author

hauntsaninja commented Feb 18, 2023

The CI failures on Python 3.11 are unrelated: ModuleNotFoundError: No module named 'setuptools_rust'
Seems like some bad caching logic

hauntsaninja added a commit to hauntsaninja/typing that referenced this pull request Feb 19, 2023
retype is no longer maintained. Since it's based on lib2to3, its corpse
is not going to be useful for too long. merge_pyi now just wraps libCST,
so mention that.

If someone seeing this is looking for things to do, I think libCST's
support here could be improved. E.g., I filed Instagram/LibCST#868
But maybe that should convert to typing.Union. I'm sure there are other
things that could be improved!
JelleZijlstra pushed a commit to python/typing that referenced this pull request Feb 20, 2023
retype is no longer maintained. Since it's based on lib2to3, its corpse
is not going to be useful for too long. merge_pyi now just wraps libCST,
so mention that.

If someone seeing this is looking for things to do, I think libCST's
support here could be improved. E.g., I filed Instagram/LibCST#868
But maybe that should convert to typing.Union. I'm sure there are other
things that could be improved!
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.

Sorry this took a while to get to. LGTM but let me ping @stroxler in case he wants to take a look too

Copy link
Contributor

@stroxler stroxler left a comment

Choose a reason for hiding this comment

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

LGTM other than I think it may be worth adding one more test.

Thanks for this!

after=after,
overwrite_existing_annotations=True,
)

Copy link
Contributor

Choose a reason for hiding this comment

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

It might be worth adding a test showing the import collector works (that's where a lot of the new logic lives, and I don't think we have anything exercising that code yet)

@zsol
Copy link
Member

zsol commented Mar 24, 2023

@hauntsaninja do you think you'll have time to add an extra test?

@hauntsaninja
Copy link
Contributor Author

Thanks for the suggestion! I added a test, then noticed that the collectors don't reach all the way into e.g. Callable[[XXX], int] because of the List.

Instead of effectively writing my own visitor to get all the nodes, I decided to just use the LibCST visiting. So in ImportedSymbolCollector we now just store a boolean to keep track of whether we're in an annotation or not. TypeCollector was a little more complicated since it was transforming the tree, so I just made a CSTTransformer.

I think the net result is overall a little simpler, but ended up being a larger change than I was expecting to make.

@hauntsaninja
Copy link
Contributor Author

cc @carljm

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.

Amazing, thanks!

@zsol zsol merged commit 2055342 into Instagram:main Apr 21, 2023
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.

5 participants