Running Ruff 0.6.9 as ruff check --isolated --select PYI030 --fix test.py deletes any subscripted types in a union with the offending Literals:
from typing import IO, Literal
InlineOption = Literal["a"] | Literal["b"] | IO[str]
becomes
from typing import IO, Literal
InlineOption = Literal["a", "b"]
Glancing through the code, it looks like this if block is just missing else { other_exprs.push(expr); }:
|
if checker.semantic().match_typing_expr(value, "Literal") { |
|
total_literals += 1; |
|
|
|
if literal_subscript.is_none() { |
|
literal_subscript = Some(value.as_ref()); |
|
} |
|
|
|
let slice = &**slice; |
|
|
|
// flatten already-unioned literals to later union again |
|
if let Expr::Tuple(tuple) = slice { |
|
for item in tuple { |
|
literal_exprs.push(item); |
|
} |
|
} else { |
|
literal_exprs.push(slice); |
|
} |
|
} |
Running Ruff 0.6.9 as
ruff check --isolated --select PYI030 --fix test.pydeletes any subscripted types in a union with the offending Literals:becomes
Glancing through the code, it looks like this
ifblock is just missingelse { other_exprs.push(expr); }:ruff/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_literal_union.rs
Lines 66 to 83 in 93eff7f