Skip to content

Inference failure with Protocol and ParamSpec #15734

Closed
@mtomassoli

Description

@mtomassoli

To Reproduce

mypy Playground

from typing import Protocol, ParamSpec, Callable, Concatenate

P = ParamSpec('P')

class FuncType(Protocol[P]):
    def __call__(self, x: int, s: str,
                 *args: P.args, **kw_args: P.kwargs) -> str: ...

def forwarder1(fp: FuncType[P], *args: P.args, **kw_args: P.kwargs) -> str:
    return fp(0, '', *args, **kw_args)

def forwarder2(fp: Callable[Concatenate[int, str, P], str],
               *args: P.args, **kw_args: P.kwargs) -> str:
    return fp(0, '', *args, **kw_args)

def my_f(x: int, s: str, d: float) -> str:
    return f"{x}, {s}, {d}"

# error: Argument 1 to "forwarder1" has incompatible type "Callable[[int, str, float], str]";
#   expected "FuncType[<nothing>]"  [arg-type]
# error: Argument 2 to "forwarder1" has incompatible type "float";
#   expected <nothing>  [arg-type]
forwarder1(my_f, 1.2)

forwarder2(my_f, 1.2)

Expected Behavior

No error found.

Actual Behavior

Argument 1 to "forwarder1" has incompatible type "Callable[[int, str, float], str]"; expected "FuncType[]" [arg-type]
Argument 2 to "forwarder1" has incompatible type "float"; expected [arg-type]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-paramspecPEP 612, ParamSpec, Concatenate

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions