numbers.Number and similar ABCs in numbers are causing mypy warnings.
To Reproduce
from numbers import Number
def f(x: Number) -> Number:
# ERROR: Operator "*" not supported for types "Literal[3]" and "Number"
return 3 * x
Additional context
We cannot build type-stable interfaces with numbers.Number, as clearly stated in Fluent Python, 2nd ed:
Sadly, the numeric tower was not designed for static type checking. The root ABC—
numbers.Number—has no methods, so if you declare x: Number, Mypy will not let
you do arithmetic or call any methods on x.
Describe the bug
numbers.Number
and similar ABCs innumbers
are causing mypy warnings.To Reproduce
Additional context
We cannot build type-stable interfaces with
numbers.Number
, as clearly stated in Fluent Python, 2nd ed: