Skip to content

Invalid solution to contravariant type variable with upper bound #2427

@ibraheemdev

Description

@ibraheemdev

For example,

class Contra[T]:
    def append(self, x: T): ...

def f[T: int](x: Contra[T]):
    ...

def _(x: Contra[str]):
    f(x) # Argument to function `f` is incorrect: Argument type `str` does not satisfy upper bound `int` of type variable `T`

Solving T to int & str = Never would avoid the assignability error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    genericsBugs or features relating to ty's generics implementation

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions