-
Notifications
You must be signed in to change notification settings - Fork 2k
Incorrect autofix for PYI030 #13685
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't workingfixesRelated to suggested fixes for violationsRelated to suggested fixes for violationshelp wantedContributions especially welcomeContributions especially welcome
Description
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); }:
ruff/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_literal_union.rs
Lines 66 to 83 in 93eff7f
| 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); | |
| } | |
| } |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingfixesRelated to suggested fixes for violationsRelated to suggested fixes for violationshelp wantedContributions especially welcomeContributions especially welcome