Skip to content

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

Description

@gschaffner

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

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-pep-646PEP 646 (TypeVarTuple, Unpack)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions