Thanks to visit codestin.com
Credit goes to github.com

Skip to content

(🐞) [1.6 regression] Can not infer ParamSpec #16296

Description

@KotlinIsland

The function d takes two functions, an original, and a wrapper. The wrapper function needs to take the original function and its parameters.

Mypy is failing to infer the paramspec for the case where the wrapper indicates poisitional parameters. Unfortunately I'm too ignorant of the specifics of ParamSpec to know if this is working correctly or not 😒, but I would think that P would get inferred as [int]

@ilevkivskyi Can you provide any insight for this case?

FYI: This did not show an error in mypy 1.5.1, it inferred P as [i: int].

from collections.abc import Callable
from typing import Concatenate, _P as P

from mypy_extensions import Arg

def o(i: int) -> None:
    print(i)

def f1(c: Callable[[Arg(int, "i")], None], /, i: int) -> None:
    c(i)

def f2(c: Callable[[int], None], /, i: int) -> None:
    c(i)


def d(f: Callable[P, None], fn: Callable[Concatenate[Callable[P, None], P], None]) -> Callable[P, None]:
    def inner(*args: P.args, **kwargs: P.kwargs) -> None:
        fn(f, *args, **kwargs)
    return inner


d(o, f1) # works
d(o, f2)
# main.py:22: error: Cannot infer type argument 1 of "d"  [misc]
# main.py:22: error: Argument 1 to "d" has incompatible type "Callable[[Callable[[int], None], int], None]"; expected "Callable[[Callable[[VarArg(Any), KwArg(Any)], None], VarArg(Any), KwArg(Any)], None]"  [arg-type]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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