As for PEP-695, maybe variance inference should exempt private members #6478
Azureblade3808
started this conversation in
Ideas
Replies: 2 comments 1 reply
-
The current behavior is consistent with the way that both pyright and mypy calculate and enforce variance for protocols. I think your argument has merit, but I'd want to understand the consensus of the broader typing community before making such a change. If you'd like, you could start a discussion in the Python typing forum. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Posted https://discuss.python.org/t/whether-private-members-should-affect-pep-695s-type-var-variance/38959 . |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The two classes in the sample are basically identical in their exposed APIs, but the private member
__l
is makingC1.T
inferred as invariant instead of covariant. I don't think this is the correct answer. Of course we can use atuple
instead of alist
to make the sample work, but in practice we may frequently use data structure with unsuitable covariance (e.g.,dict
) in the private part. I'd suggest that only public members of a class get into consideration when type-var variance is being inferred.Beta Was this translation helpful? Give feedback.
All reactions