Skip to content

bool is accepted for TypeGuard #10489

Closed
Closed
@JelleZijlstra

Description

@JelleZijlstra

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions