-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 autotyping-like return type inference for annotation rules #8643
Conversation
114213c
to
8950bff
Compare
ec39700
to
8ae9236
Compare
crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs
Outdated
Show resolved
Hide resolved
|
||
// Wrap in a bitwise union (e.g., `int | float`). | ||
Some(union(&names)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine but is there any specific reason we're not implementing the typing.Union
variant for pre 3.10?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just complexity and/or laziness.
f645062
to
aa89dd0
Compare
|
Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
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.,
float
instead ofint | float
) and deal with implicit returns (return
without a value).Closes #1640 (though we could open a separate issue for referring parameter types).
Closes #8213.
Test Plan
cargo test