-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Invalid handling type narrowing with inf/float due to duck typing #12824
Comments
Sorry but how is this defined there? How can't this be a bug?
It doesn't say: If I accept IMHO this is still a bug (at least when declaring explicitly!). So I kindly ask you @ethanhs to re-open. |
Sorry, I think I was confused as to what you were expecting. Let me back up a bit more. If I have an argument that takes However, if I think the real bug here is the first reveal_type should probably simplify |
I agree this is a bug. @ethanhs, you're correct that PEP 484 specifies that Mypy is applying type narrowing for |
Bug Report
Due to duck typing handling type narrowing within a function accepting both int and float (even explicitly) doesn't work correctly.
To Reproduce
Consider this code, that actually leads to a type error
Expected Behavior
I would expect that MyPy would warn me and that the expected reveal_type after the the isinstance call is
int | float
This should be even the case, if
int
is not explicitly given.Consider the modification of above:
would still raise a runtime type error and no typing error at all.
Also handling all duck types explicitly as unions when type narrowing would probably handle the non reachable bugs described in
#12643.
This is also suggested in #11516
Actual Behavior
No error / warning raised by MyPy
Your Environment
See MyPy Playground
Maybe related issues:
#11511
The text was updated successfully, but these errors were encountered: