Skip to content

PEP 483 has invalid variance example #133353

@cowfoodbagman

Description

@cowfoodbagman

PEP 483 explains variance and provides this example:

T_co = TypeVar('T_co', Employee, Manager, covariant=True)
T_contra = TypeVar('T_contra', Employee, Manager, contravariant=True)

class Base(Generic[T_contra]):
    ...

class Derived(Base[T_co]):
    ...

Mypy gives this error when I try this example out:
error: Variance of TypeVar "T_co" incompatible with variance in parent type [type-var]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions