-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Safer treatment of @runtime protocols in isinstance() #3827
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
Comments
This is a follow-up for #3132 |
I'm curious how far this should go. With the |
TBH I am not sure myself, this is why "discussion needed" label :-) One possible option is to erase types of all attributes (both methods and variables) completely. But maybe this is too radical, and we can for example only erase types of instance variables, but keep the fact that methods are callable (so that they will become |
Mypy no longer considers the code in the original example unreachable, so I'm closing this issue. (If there's more to be done, feel free to reopen.) |
Currently,
isinstance
with protocols uses the same logic as with nominal classes, i.e. only erases the type variables, but sometimes this may be not safe (as discussed in PEP 544), for example:The idea is to perform a "deeper" erasure (setting all attribute types to
Any
) when consideringisinstance()
with protocols, thus mimicking the runtime behaviour.The text was updated successfully, but these errors were encountered: