Open
Description
from typing import TypeVar
T = TypeVar("T", int, str)
def foo() -> T:
return 1 # error: Incompatible return value type (got "int", expected "str") [return-value]
def bar() -> T:
return "" # error: Incompatible return value type (got "str", expected "int") [return-value]
https://mypy-play.net/?mypy=latest&python=3.10&gist=442fc0f6332aa02d4dc509460b91536a
i think the error message should be something like:
Incompatible return value type (got "int", expected "T")
or maybe something more descriptive, like how typescript puts it:
'T' could be instantiated with an arbitrary type which could be unrelated to 'number'.