Skip to content

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 types accept multiple arguments and it is clearer to specify them as a single literal.

Example#

from typing import Literal

field: Literal[1] | Literal[2]

Use instead:

from typing import Literal

field: Literal[1, 2]