Skip to content

Is not reporting on covariant TypeVars in Protocols when using it for a private variable intentional? #8841

Answered by erictraut
Daraan asked this question in Q&A
Discussion options

You must be logged in to vote

I added an exemption for variables with protected or private names based on this discussion. This also affects auto-invariance calculations for TypeVars that use the new (PEP 695) syntax.

In hindsight, I wonder if this was the right decision — at least for protected variables. I think it's justified for private variables because they cannot be modified outside of the class and cannot be overridden by subclasses (because of name mangling), but I'm not as sure about variables with protected names.

The Python typing spec is silent on this topic. Because this is a gray area, I'm reluctant to change pyright's behavior unless/until there is consensus in the community about the "correct" behavio…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Daraan
Comment options

@Daraan
Comment options

Answer selected by Daraan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants