Skip to content

Clarification on how Typevars in a generic function should resolve #2142

@kamalfarahani

Description

@kamalfarahani

Hi, regarding the issue opened here:

astral-sh/ty#2255

Can you please provide clarification on how TypeVars in a function like func in the below code should be resolved?

class A:
    pass

class B(A):
    pass

class C(A):
    pass

def func[T: A](x: T, y: T) -> T:
    ...

func(B(), C()) # I think this should raise a type error by type checkers but no type checker (mypy, pyright, etc) raise an error for this

Please look at these comments:
astral-sh/ty#2255 (comment)
astral-sh/ty#2255 (comment)
astral-sh/ty#2255 (comment)
astral-sh/ty#2255 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions