redundant-numeric-union (PYI041)#
Derived from the flake8-pyi linter.
What it does#
Checks for union annotations that contain redundant numeric types (e.g.,
int | float
).
Why is this bad?#
In Python, int
is a subtype of float
, and float
is a subtype of
complex
. As such, a union that includes both int
and float
is
redundant, as it is equivalent to a union that only includes float
.
For more, see PEP 3141, which defines Python's "numeric tower".
Unions with redundant elements are less readable than unions without them.
Example#
Use instead: