T: return a + b print(foo("1", "2")) mypy: error: Incompatible return value type (got "str", expect" /> T: return a + b print(foo("1", "2")) mypy: error: Incompatible return value type (got "str", expect" /> T: return a + b print(foo("1", "2")) mypy: error: Incompatible return value type (got "str", expect"/>

mypy Incompatible return value type with TypeVar(bound=str)

70 Views Asked by At
T = TypeVar("T", bound=str)


def foo(a: T, b: T) -> T:
    return a + b


print(foo("1", "2"))

mypy: error: Incompatible return value type (got "str", expected "T") [return-value]

I dont understand how to fix this problem(using bound).

0

There are 0 best solutions below