Skip to content

False positive for class patterns when Callable is used #16617

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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