Reported by @mohabusama on gitter -- short version:
from typing import *
T = TypeVar('T', List[int], Dict)
Processor = Callable[[T], None]
def output2(inp: T, processor: Processor) -> T:
processor(inp)
def process_dict(inp: Dict) -> None:
print(inp.keys())
output2([1, 2, 3], process_dict)
There should be an error on the last line, but there isn't. Surrounding the line with reveal_type() shows that the inferred value for T is List[int].
If we expand the type alias Processor inline in the signature of output2() we get the expected error:
__tmp__.py:8: error: Argument 2 to "output2" has incompatible type Callable[[Dict[Any, Any]], None]; expected Callable[[List[int]], None]
This feels like a flaw in @ilevkivskyi's #2378 (which added support for type aliases containing type variables).
Reported by @mohabusama on gitter -- short version:
There should be an error on the last line, but there isn't. Surrounding the line with
reveal_type()shows that the inferred value forTisList[int].If we expand the type alias
Processorinline in the signature ofoutput2()we get the expected error:This feels like a flaw in @ilevkivskyi's #2378 (which added support for type aliases containing type variables).