TeamGraphix / graphix

measurement-based quantum computing (MBQC) compiler and simulator
https://graphix.readthedocs.io
Apache License 2.0
64 stars 21 forks source link

[Bug]: `numbers.Number` causes type warning #203

Open EarlMilktea opened 3 months ago

EarlMilktea commented 3 months ago

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.