Skip to content

Incorrect narrowing for class pattern when Callable is used #6648

@randolf-scholz

Description

@randolf-scholz

Possibly even bug, maybe related to #6600 ?

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:
            func()

I guess the issue is that if T is callable, then its signature might be incompatible? But for completely unknown T, I'd assume that func should be inferred as the widest possible type Callable[..., Any].

Metadata

Metadata

Assignees

No one assigned

    Labels

    addressed in next versionIssue is fixed and will appear in next published versionbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions