Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic matching error when tuple-unpacking result #16310

Open
msullivan opened this issue Oct 21, 2023 · 0 comments
Open

Generic matching error when tuple-unpacking result #16310

msullivan opened this issue Oct 21, 2023 · 0 comments
Labels
bug mypy got something wrong topic-inference When to infer types or require explicit annotations topic-type-variables topic-union-types

Comments

@msullivan
Copy link
Collaborator

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]
@msullivan msullivan added the bug mypy got something wrong label Oct 21, 2023
@ilevkivskyi ilevkivskyi added topic-type-variables topic-union-types topic-inference When to infer types or require explicit annotations labels Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-inference When to infer types or require explicit annotations topic-type-variables topic-union-types
Projects
None yet
Development

No branches or pull requests

2 participants