Skip to content

False positive for class patterns when Callable is used #16617

@erictraut

Description

@erictraut

Mypy generates a false positive with the following code.

from collections.abc import Callable
from typing import TypeVar

T = TypeVar("T")

def foo(obj: T | Callable[..., T]) -> None:
    match obj:
        case Callable() as func:  # error: Expected type in class pattern; found "typing._SpecialForm"
            func()

FWIW, pyright was also not handling this case correctly.

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