Skip to content

(🐞) TypeGuard passed to a TypeVar becomes Any, not bool #17117

@KotlinIsland

Description

@KotlinIsland

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:
    return fn(1)

reveal_type(f(guard))  # Any

This should be bool, not Any

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