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

Number is not compatible with int #8348

Closed
theRealProHacker opened this issue Jul 20, 2022 · 1 comment
Closed

Number is not compatible with int #8348

theRealProHacker opened this issue Jul 20, 2022 · 1 comment

Comments

@theRealProHacker
Copy link

I tried to hold the code as minimal as possible

num: Number = 0

If we run mypy over this:

error: Incompatible types in assignment (expression has type "int", variable has type "Number")

This is unexpected. There shouldn't be an error because Number>int or in other words isinstance(0, Number) is True.
Instead, there should be no error.
I can't tell if this is a bug in mypy, but I think it rather is a typing problem.

Python Version 3.10.1
OS: Windows 10 (Although, I think this shouldn't make a difference)

@AlexWaygood
Copy link
Member

This is a very well-known problem. For a ground-up explanation of what's going on here, you might like my StackOverflow answer to this question here: https://stackoverflow.com/questions/69334475/how-to-hint-at-number-types-i-e-subclasses-of-number-not-numbers-themselv

For pre-existing discussions on what to do about this, you may be interested in:

@AlexWaygood AlexWaygood closed this as not planned Won't fix, can't repro, duplicate, stale Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants