Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Incorrect autofix for PYI030 #13685

Closed
yut23 opened this issue Oct 8, 2024 · 1 comment · Fixed by #13727
Closed

Incorrect autofix for PYI030 #13685

yut23 opened this issue Oct 8, 2024 · 1 comment · Fixed by #13727
Labels
bug Something isn't working fixes Related to suggested fixes for violations help wanted Contributions especially welcome

Comments

@yut23
Copy link

yut23 commented Oct 8, 2024

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

@zanieb zanieb added bug Something isn't working fixes Related to suggested fixes for violations labels Oct 8, 2024
@MichaReiser MichaReiser added the help wanted Contributions especially welcome label Oct 8, 2024
@diceroll123
Copy link
Contributor

Good catch, that was exactly the fix! 😄

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working fixes Related to suggested fixes for violations help wanted Contributions especially welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants