March 17, 2022
9:38 a.m.
On Thu, Mar 17, 2022 at 2:03 AM Jelle Zijlstra <jelle.zijlstra@gmail.com> wrote:
I think that would give the wrong semantics for most cases. This case has been discussed on this list before and I believe different type checkers currently interpret it differently. The difference is about whether T is scoped to the function or to the Callable. It would be nice to have a way to explicitly scope the TypeVar to the Callable, but no elegant solution comes to mind.
Here's an ugly solution:
def get_identity_func() -> (T := TypeVar("T") and Callable[[T], T]): ...
def get_identity_func() -> (lambda T: Callable[[T], T]): ... :-)