Skip to content

Check class type parameter variance violations in inheritance #736

@JukkaL

Description

@JukkaL

In generic inheritance, we can't change the variance of a type from invariant to covariant/contravariant. This should probably be rejected:

IV = TypeVar('IV')
CV = TypeVar('CV', covariant=True)

class A(Generic[IV]): ... # Bunch of methods
class B(A[CV], Generic[CV]): pass  # Error, type variable should be invariant

Going from covariant to invariant is fine (for example, List has to do this since it subclasses Sequence, which is covariant).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions