-
Notifications
You must be signed in to change notification settings - Fork 194
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
Add support for methods with func type comment excluding self/cls #622
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PEP 484 doesn't really specify carefully how function type comments should work on methods, but since usually the type of `self` / `cls` is automatic, most use cases choose to only annotate the other arguments. As a result, this commit modifies our codemod so that non-static methods can specify either all the arguments, or all but one of them. We'll correctly zip together the inline and func-type-comment types either way, typically getting no type for `cls` or `self`. We accomplish this by using matchers to trigger the visit method for FunctionDef rather than using visit_FunctionDef, which gives us enough context to determine when a function def is a regular function versus a method (plus also matching the decorators against `@staticmethod`, so that we trigger the normal function logic in that case).
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
Jan 22, 2022
Codecov Report
@@ Coverage Diff @@
## main #622 +/- ##
==========================================
- Coverage 94.78% 94.78% -0.01%
==========================================
Files 245 245
Lines 25256 25281 +25
==========================================
+ Hits 23940 23963 +23
- Misses 1316 1318 +2
Continue to review full report at Codecov.
|
zsol
approved these changes
Jan 25, 2022
Fix incorrect types due to copypasta Co-authored-by: Zsolt Dollenstein <[email protected]>
This was referenced Jan 28, 2022
1 task
1 task
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
PEP 484 doesn't really specify carefully how function type
comments should work on methods, but since usually the type of
self
/cls
is automatic, most use cases choose to only annotatethe other arguments.
As a result, this commit modifies our codemod so that non-static
methods can specify either all the arguments, or all but one of
them. We'll correctly zip together the inline and func-type-comment
types either way, typically getting no type for
cls
orself
.We accomplish this by using matchers to trigger the visit
method for FunctionDef rather than using visit_FunctionDef, which gives
us enough context to determine when a function def is a regular
function versus a method (plus also matching the decorators against
@staticmethod
, so that we trigger the normal function logic inthat case).
Test Plan
I added a new test verifying various method cases: static and non-static,
with and without annotations of
self
/cls
in the func type comment,with and without inline type comments.