-
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
[ruff
] Add never-union
rule to detect redundant typing.NoReturn
and typing.Never
#9217
Conversation
This should be fixable but isn't trivial, working on it separately. |
128adf3
to
024a2c5
Compare
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
RUF020 | 3 | 3 | 0 | 0 | 0 |
Formatter (stable)
✅ ecosystem check detected no format changes.
Formatter (preview)
✅ ecosystem check detected no format changes.
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
enum UnionLike { | ||
/// E.g., `typing.Union[int, str]` | ||
Union, |
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: I struggled with the name because I incorrectly assumed it represents int | str
. Maybe TypingUnion
? or Typing
and BinOp
?
} | ||
|
||
/// RUF020 | ||
pub(crate) fn never_union<'a>(checker: &mut Checker, expr: &'a Expr) { |
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.
Unrelated to this PR: Hmm, one downside of quoting runtime only type annotations is that it makes all lint-rules useless because we don't parse string annotations...
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.
We actually do!
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.
Cool!
Interesting notes in the ecosystem e.g.
|
024a2c5
to
cac256b
Compare
Summary
Adds a rule to detect unions that include
typing.NoReturn
ortyping.Never
. In such cases, the use of the bottom type is redundant.Closes #9113.
Test Plan
cargo test