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

Incompatible type when using ParamSpec #12169

Closed
NeilGirdhar opened this issue Feb 12, 2022 · 3 comments
Closed

Incompatible type when using ParamSpec #12169

NeilGirdhar opened this issue Feb 12, 2022 · 3 comments
Labels
bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate

Comments

@NeilGirdhar
Copy link
Contributor

NeilGirdhar commented Feb 12, 2022

Maybe I've misunderstood how parameter specification variables are supposed to used, but this is what I have:

from typing import TypeVar, Generic, ParamSpec, Protocol, Callable
from functools import partial

T = TypeVar("T", covariant=True)
P = ParamSpec("P")

class JittedFunction(Protocol, Generic[P, T]):
  def __call__(self, *args: P.args, **kwargs: P.kwargs) -> T:
    ...

  def lower(self) -> int:
    ...

def jit(fun: Callable[P, T], *, x: int) -> JittedFunction[P, T]:
    pass

@partial(jit, x=2)  # error: Argument 1 to "partial" has incompatible type "Callable[[Callable[P, Any], NamedArg(int, 'x')], JittedFunction[P]]"; expected "Callable[..., JittedFunction[P]]"  [arg-type]
def f(y: int) -> int:
    return y
@NeilGirdhar NeilGirdhar added the bug mypy got something wrong label Feb 12, 2022
@NeilGirdhar NeilGirdhar reopened this Feb 12, 2022
@erictraut
Copy link

Your code looks correct to me. This type checks without errors in pyright.

@NeilGirdhar
Copy link
Contributor Author

Thanks @erictraut ! You're always very helpful.

@ilevkivskyi
Copy link
Member

Original example works on master, 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
Development

Successfully merging a pull request may close this issue.

4 participants