Skip to content

Variance of arguments for Generic ABC vs Generic Protocol #1793

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

You must be logged in to vote

do Generic ABCs just not get typed checked for variance

Full TypeVar variance consistency is checked only for protocols (as indicated in the typing spec), not for nominal class definitions (including ABCs). Both pyright and mypy do minimal checks for improper usage of covariant and contravariant TypeVars within method parameters and return types, but this isn't the same as full variance consistency checks.

The new TypeVar syntax introduced in PEP 695 eliminates the need to worry about variance consistency because variance is calculated by the type checker based on usage. Pyright has had support for PEP 695 for a long time already, and the next release of mypy will also include support f…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@kbehlers
Comment options

Answer selected by kbehlers
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