Skip to content

Generic matching error when tuple-unpacking result #16310

Open
@msullivan

Description

@msullivan

Here, in caller_bad, immediately unpacking the result leads to the second type variable getting bound to int | str instead of just int

from typing import TypeVar, Generic

T = TypeVar('T')
U = TypeVar('U')

class Test(Generic[T, U]):
    pass

def test(gen: Test[T, U]) -> tuple[T, U | str]:
    raise NotImplementedError

def call() -> Test[str, int]:
    raise NotImplementedError

def caller_bad() -> None:
    x, y = test(call())

def caller_ok() -> None:
    res = test(call())
    x, y = res
_bug.py:16: error: Argument 1 to "test" has incompatible type "Test[str, int]"; expected "Test[str, Union[int, str]]"  [arg-type]

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions