Skip to content

Incompatible type when using ParamSpec #12169

Closed
@NeilGirdhar

Description

@NeilGirdhar

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

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