redundant-numeric-union (PYI041)#
Derived from the flake8-pyi linter.
What it does#
Checks for parameter annotations that contain redundant unions between
builtin numeric types (e.g., int | float).
Why is this bad?#
The typing specification states:
Python’s numeric types
complex,floatandintare not subtypes of each other, but to support common use cases, the type system contains a straightforward shortcut: when an argument is annotated as having typefloat, an argument of typeintis acceptable; similar, for an argument annotated as having typecomplex, arguments of typefloatorintare acceptable.
As such, a union that includes both int and float is redundant in the
specific context of a parameter annotation, as it is equivalent to a union
that only includes float. For readability and clarity, unions should omit
redundant elements.
Example#
Use instead: