Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bool is accepted for TypeGuard #10490

Closed
JelleZijlstra opened this issue May 17, 2021 · 1 comment
Closed

bool is accepted for TypeGuard #10490

JelleZijlstra opened this issue May 17, 2021 · 1 comment
Labels
bug mypy got something wrong

Comments

@JelleZijlstra
Copy link
Member

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

@JelleZijlstra JelleZijlstra added the bug mypy got something wrong label May 17, 2021
@JelleZijlstra
Copy link
Member Author

Duplicate of #10489 (GitHub seems to be having some issues today)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant