Clarification on the variance of self
on Protocols
#3373
MathiasSven
started this conversation in
General
Replies: 1 comment 7 replies
-
Converting to discussion. |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am not sure pyright is the right place to open this as a bug report as I am not sure what the consensus is on the expected behavior, regardless to me it seems that when annotating a
Protocol
this construction should be allowed:Currently mypy accepts this, however pyright complains that since the type variable is used as a parameter it ought to be contravariant, conversely if you set the type variable to contravariant, then mypy complains about the opposite. Due to the nature of
self
should it not be treated as covariant?As to how this could be useful, I think broadly not so much, but it does is give you access to the type when annotating functions with such a protocol. In my specific use case:
Beta Was this translation helpful? Give feedback.
All reactions