Closed
Description
Consider this example:
from typing import Any, Callable
from typing_extensions import TypeGuard
def notguard(x: Any) -> bool: ...
def hof2(func: Callable[[Any], TypeGuard[int]]): ...
hof2(notguard)
Mypy throws no errors, but a bool is not a TypeGuard.
Relatedly, this example prints bool
:
from typing import Any, Callable, List, TypeVar
from typing_extensions import TypeGuard
T = TypeVar("T")
def notguard(x: Any) -> bool: ...
def my_filter(func: Callable[[Any], TypeGuard[T]]) -> List[T]: ...
reveal_type(my_filter(notguard))
(Extracted from work by @erictraut and @gvanrossum at python/typeshed#5406.)