Skip to content

PEP-612 ParamSpec with high-order function error. #12595

Closed
@YouJiacheng

Description

@YouJiacheng

mypy==0.950 from https://github.com/python/mypy/tree/release-0.950
python==3.9.11

from typing import TypeVar, Callable
from typing_extensions import Concatenate, ParamSpec, Protocol

T_co = TypeVar('T_co', covariant=True)
T = TypeVar('T')
P = ParamSpec('P')

class Wrapped(Protocol[P, T_co]):
  def __call__(self, *args: P.args, **kwargs: P.kwargs) -> T_co:
    pass

def jit(f: Callable[P, T], *, a: bool) -> Wrapped[P, T]:
    return f

_T = TypeVar('_T')
_P = ParamSpec('_P')

def _make_factory(
    transform: Callable[Concatenate[Callable[P, T], _P], _T]
) -> Callable[_P, Callable[[Callable[P, T]], _T]]:
    return lambda *args, **kwargs: lambda f: transform(f, *args, **kwargs)

_make_jit = _make_factory(jit)
@_make_jit(a=True) # line 24
def f(x: int, y: int):
    return x + y

f(0, 0) # line 28
paramspec.py:24: error: Argument 1 has incompatible type "Callable[[int, int], Any]"; expected "Callable[[VarArg(<nothing>), KwArg(<nothing>)], <nothing>]"
paramspec.py:28: error: Argument 1 to "__call__" of "Wrapped" has incompatible type "int"; expected <nothing>
paramspec.py:28: error: Argument 2 to "__call__" of "Wrapped" has incompatible type "int"; expected <nothing>
Found 3 errors in 1 file (checked 1 source file

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