https://github.com/python/mypy/labels/topic-typeguard
topic-type-variables
from typing import TypeGuard, TypeVar, Callable
T = TypeVar("T")
def guard(x: object) -> TypeGuard[str]:
return True
def f(fn: Callable[[object], T]) -> T: ...
a = f(guard) # error: Argument 1 to "f" has incompatible type "Callable[[object], TypeGuard[str]]"; expected "Callable[[object], str]" [arg-type]
reveal_type(a) # str