Skip to content

(🐞) generics not resolving correctly when multiple TypeVars don't meet the expected type #17553

Closed
@KotlinIsland

Description

@KotlinIsland
from typing import TypeVar

T1 = TypeVar("T1")
T2 = TypeVar("T2")


def f(t1: T1, t2: T2) -> T1 | T2:
    return t1


a: int = f(1, None) or 1  # error: Argument 2 to "f" has incompatible type "None"; expected "int"  [arg-type]

def f1(t1: T1, t2: T1) -> T1:
    return t1

b: int = f1(1, None) or 1  # no error

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions