-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Disallow type(x) if x has a protocol type #16919
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
I think an error should not be reported for calling The example here doesn't show any problematic code. It only shows mypy reporting incorrect information. The fact that mypy reports incorrect information (in one version) is not a reason to report an error with that code (in a later version). In the example of the linked issue, there is problematic code, but the problem is not in calling A better solution would be that if Then it won't assume that it has a |
or maybe the return type should be |
Fixes python#16919, fixes python#16890
Fixes python#16919, fixes python#16890
Fixes python#16919, fixes python#16890
What exactly does this sentence mean? The following raises no errors at runtime: import typing
cls = type(typing)
assert isinstance(cls, type) # ✅ Apologies if I am missing the obvious... Using |
|
Modules can implement protocols, so
type(x)
is not necessarily a type object ifx
has a protocol type.It's probably best to to generate an error if
type
is called on an object with a protocol type, as suggested by @hauntsaninja in #16890 (comment).See #16890 for more context.
The text was updated successfully, but these errors were encountered: