mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Callables like `operator.call` produce `arg-type` error with callables that take `*args: Unpack[Ts]` and >= 1 keyword argument

Open gschaffner opened this issue 1 year ago • 0 comments

Bug Report

operator.call and similar ParamSpec callables (e.g. concurrent.futures.Executor.submit) produce an arg-type error when doing call(fn, fn2, some_kwarg=...) where fn has signature (fn2: Callable[[Unpack[Ts]], T], *args: Unpack[Ts], some_kwarg: ...) -> ...

this looks like a TypeVarTuple analog of #16405.

To Reproduce

import operator
from collections.abc import Callable
from typing import TypeVar
from typing import TypeVarTuple
from typing import Unpack

T = TypeVar("T")
Ts = TypeVarTuple("Ts")


def run(func: Callable[[Unpack[Ts]], T], *args: Unpack[Ts], some_kwarg: str = "asdf") -> T:
    raise NotImplementedError


def foo() -> str:
    raise NotImplementedError


run(foo)  # OK
operator.call(run, foo)  # OK
run(foo, some_kwarg="a")  # OK
operator.call(run, foo, some_kwarg="a")
# error: Argument 1 to "call" has incompatible type "Callable[[Callable[[VarArg(*Ts)],
# T], VarArg(*Ts), DefaultNamedArg(str, 'some_kwarg')], T]"; expected
# "Callable[[Callable[[], str], str], str]"  [arg-type]

Expected Behavior

no error.

Actual Behavior

see comments in the reproducer above.

Your Environment

  • Mypy version used: 1.7.1 (compiled) & latest master (uncompiled)
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: CPython 3.12.1

gschaffner avatar Dec 14 '23 12:12 gschaffner