Add autotyping-like return type inference for annotation rules#8643
Merged
charliermarsh merged 3 commits intomainfrom Nov 14, 2023
Merged
Add autotyping-like return type inference for annotation rules#8643charliermarsh merged 3 commits intomainfrom
charliermarsh merged 3 commits intomainfrom
Conversation
114213c to
8950bff
Compare
ec39700 to
8ae9236
Compare
dhruvmanila
reviewed
Nov 13, 2023
Comment on lines
+79
to
+81
|
|
||
| // Wrap in a bitwise union (e.g., `int | float`). | ||
| Some(union(&names)) |
Member
There was a problem hiding this comment.
nit: not critical but maybe we could update union to take an iterator instead to avoid allocating a vector here
| // Wrap in a bitwise union (e.g., `int | float`). | ||
| Some(union(&names)) | ||
| } | ||
| ResolvedPythonType::Union(_) => None, |
Member
There was a problem hiding this comment.
I think it's fine but is there any specific reason we're not implementing the typing.Union variant for pre 3.10?
Member
Author
There was a problem hiding this comment.
Just complexity and/or laziness.
f645062 to
aa89dd0
Compare
Contributor
|
dhruvmanila
reviewed
Nov 14, 2023
dhruvmanila
approved these changes
Nov 14, 2023
Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
This PR adds (unsafe) fixes to the flake8-annotations rules that enforce missing return types, offering to automatically insert type annotations for functions with literal return values. The logic is smart enough to generate simplified unions (e.g.,
floatinstead ofint | float) and deal with implicit returns (returnwithout a value).Closes #1640 (though we could open a separate issue for referring parameter types).
Closes #8213.
Test Plan
cargo test