Consider the following code:
from typing import Callable, TypeVar T = TypeVar('T') def middle_man( producer: Callable[, T], consumer: Callable[[T], None] ) -> None: consumer(producer()) middle_man( lambda: "HELLO", lambda s: print(s.lower()) )
This code runs without error and works as expected, however, mypy fails to infer the type of
s in the second lambda, giving the error:
"object" has no attribute "lower"`
Right now, my only workaround is either to cast
s, which can be a pain in a more complex lambda or with a more complex type, or to add
# type: ignore, which I'd rather not do.
Is there a better workaround, or a proper way to get mypy to recognize the type?