Skip to content

redundant-literal-union (PYI051)#

Derived from the flake8-pyi linter.

What it does#

Checks for the presence of redundant Literal types and builtin super types in an union.

Why is this bad?#

The use of Literal types in a union with the builtin super type of one of its literal members is redundant, as the super type is strictly more general than the Literal type.

For example, Literal["A"] | str is equivalent to str, and Literal[1] | int is equivalent to int, as str and int are the super types of "A" and 1 respectively.

Example#

from typing import Literal

A: Literal["A"] | str

Use instead:

from typing import Literal

A: Literal["A"]