Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
EarlMilktea opened this issue Aug 26, 2024 · 0 comments
Open

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

EarlMilktea opened this issue Aug 26, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@EarlMilktea
Copy link
Contributor

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.

@EarlMilktea EarlMilktea added the bug Something isn't working label Aug 26, 2024
@TeamGraphix TeamGraphix deleted a comment Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant