-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Better error message for rejected protocol subtyping due to mutability #5752
Comments
This is not a bug, but an actual type error, please read this https://mypy.readthedocs.io/en/latest/common_issues.html#covariant-subtyping-of-mutable-protocol-members-is-rejected |
On the second thought, maybe we should add this link to the error message? It is not obvious that this is rejected because of the mutability (especially that mypy allows this for nominal subclasses), but on the other hand it is quite rare case, so I am not sure here. |
Yeah, I was just about comment that it would be helpful if the error message indicated that the protocol was rejected due to mutability. Doesn't make a huge difference to me now that I know, but might be helpful for others that run into this? Edit: actually if it's possible to differentiate between the two cases, I think there it'd be better if there were two distinct error messages for mutability vs incompatible types (i.e. dont even say incompatible types at all here). Also a full link is maybe not necessary; a reasonably informative message should give users enough to search. |
OK, let's see what others think. @JukkaL @gvanrossum should we add a note (probably with the link) to this error message? |
I do think the error should be clearer, and if we can link to that section in the docs when we find covariant subtyping might be assumed that would well help. I wonder if the OP has thought of adding |
OK, I am re-opening with another title. |
Thanks, I really appreciate the responsiveness and the dedication to usability! |
Closing as a duplicate of #6002 |
It appears that Union types for Protocol attributes aren't recognized.
Repro example:
Failing output:
Argument 1 to "dec" has incompatible type "Type[Thing]"; expected "Type[HasFoo]"
Misc info:
Tested with both mypy 0.630 and mypy master (e12be3b), run with
--strict
The text was updated successfully, but these errors were encountered: