-
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
idea: Add rule for flattening nested Literal
s
#7881
Comments
++ |
Could this not be part of PYI030 itself (https://docs.astral.sh/ruff/rules/unnecessary-literal-union/)? |
As its name says that is field: Literal[1] | Literal[2] # FIX: Literal[1, 2] For field: Literal[1, Literal[2]] # FIX: Literal[1, 2] |
I've implemented this in as part of #7934, but of course this is strictly for literals. |
It could. But can also be a new code. It was not implemented in flake8-pyi for the sole reason it was not deemed worth the effort for typeshed. PyCQA/flake8-pyi#425 Also note the existence of Y061 PyCQA/flake8-pyi#435 |
From PEP 586,
Literal[Literal[Literal[1, 2, 3], "foo"], 5, None]
is equivalent toLiteral[1, 2, 3, "foo", 5, None]
Currently there's no rule I know of that would unfurl/flatten a literal structure like this. Would be neat!
I came across this while fiddling with #7880.
The text was updated successfully, but these errors were encountered: