Open
Description
Two unbound TypeVars A
and B
can potentially be the same:
from typing import Callable, Iterable, TypeVar
A = TypeVar("A")
B = TypeVar("B")
def identity(x: A) -> A:
return x
# ok
def _map(queue: Iterable[B], function: Callable[[B], A]) -> Iterable[A]:
return map(function, queue)
# fails
def _map2(queue: Iterable[B], function: Callable[[B], A] = identity) -> Iterable[A]:
return map(function, queue)
The introduced default keyword argument leads to the following unexpected error:
error: Incompatible default for argument "function" (default has type "Callable[[A], A]", argument has type "Callable[[B], A]")
I'm using mypy 0.740.