unnecessary-literal-union (PYI030)
Derived from the flake8-pyi linter.
Fix is sometimes available.
What it does
Checks for the presence of multiple literal types in a union.
Why is this bad?
Literal["foo", 42]
has identical semantics to
Literal["foo"] | Literal[42]
, but is clearer and more concise.
Example
Use instead:
Fix safety
This fix is marked unsafe if it would delete any comments within the replacement range.
An example to illustrate where comments are preserved and where they are not:
from typing import Literal
field: (
# deleted comment
Literal["a", "b"] # deleted comment
# deleted comment
| Literal["c", "d"] # preserved comment
)