[Bug]: `numbers.Number` causes type warning
Opened this issue · 0 comments
EarlMilktea commented
Describe the bug
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.