[ruff] Add never-union rule to detect redundant typing.NoReturn and typing.Never#9217
[ruff] Add never-union rule to detect redundant typing.NoReturn and typing.Never#9217charliermarsh merged 1 commit intomainfrom
ruff] Add never-union rule to detect redundant typing.NoReturn and typing.Never#9217Conversation
|
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.
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.
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...
|
Interesting notes in the ecosystem e.g.
|
024a2c5 to
cac256b
Compare
Summary
Adds a rule to detect unions that include
typing.NoReturnortyping.Never. In such cases, the use of the bottom type is redundant.Closes #9113.
Test Plan
cargo test