Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
YouJiacheng opened this issue Apr 15, 2022 · 1 comment
Closed

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

YouJiacheng opened this issue Apr 15, 2022 · 1 comment
Labels
bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate

Comments

@YouJiacheng
Copy link

YouJiacheng commented Apr 15, 2022

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
@ilevkivskyi
Copy link
Member

This works on master with --new-type-inference, likely fixed by #15837

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate
Projects
None yet
3 participants