-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request: More autofixes for redundant-none-literal
/PYI061
#14537
Comments
I’d like to take this up. |
So, if I understand this correctly the rule from typing import Literal
a: Literal[None]
b: Literal[1, 2, 3, "foo", 5, None] which gets auto-fixed to: from typing import Literal
a: None
b: Literal[1, 2, 3, "foo", 5, None] Here, I can see that the second statement isn't getting fixed. Is this the issue about? To fix things like this adhering to PYI061? |
@kiran-4444 Exactly. Even the error message alludes to this being possible to autofix, just not implemented: PYI061 `Literal[None, ...]` can be replaced with `Literal[...] | None`
|
3 | a: None
4 | b: Literal[1, 2, 3, "foo", 5, None]
| ^^^^ PYI061
|
= help: Replace with `Literal[...] | None` |
This seems to have been resolved by #14872. |
Yep, Looks like this is closed by #14872 ! |
Hmmm, I'm on
|
Fixes just fine for me in the playground: https://play.ruff.rs/fd2b0091-14e2-44e2-9208-983d8e9c1862 |
I get it: on Python 3.9 the fix isn't offered at all rather than being "unsafe" (or using
So I guess the fix being marked as unsafe but available was also left aside in that PR. I'll open a different issue for that specific use-case ! Done here: #15795 |
https://docs.astral.sh/ruff/rules/redundant-none-literal mentions that the rule is sometimes autofixable, but I landed on the following cases which are not autofixed and I believe should:
The command you invoked
ruff check --fix --preview --select=PYI061 --isolated
The current Ruff version (
ruff --version
).ruff 0.8.0
The text was updated successfully, but these errors were encountered: