-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Unsoundness involving Literals and bounded type vars #4108
Comments
This is an ambiguity in the type system. Both pyright and mypy use heuristics to determine whether to preserve literals within the constraint solver. I've spent a lot of time tuning these heuristics so they produce the right results the vast majority of the time, but there will inevitably be cases where the heuristic fails. This is one of those cases. I don't see a way fix this case without breaking many more common cases. If you feel strongly about this case or think that it's potentially more common than I'm assuming, we could discuss the issue in python/typing to see if someone has a general solution. |
Describe the bug
Inferring literals when TypeVars have bounds may not be sound.
To Reproduce
pyright gives me:
When obviously the value is 2.
Note that mypy matches pyright's (unsound) behaviour.
This was originally filed on typeshed, but only came to my attention recently:
python/typeshed#8230
This was worked around for builtins.sum in python/typeshed#8231 , but there's clearly a more general problem here.
The text was updated successfully, but these errors were encountered: