Skip to content

Incorrect autofix for PYI030 #13685

@yut23

Description

@yut23

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);
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixesRelated to suggested fixes for violationshelp wantedContributions especially welcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions