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

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

Open
gschaffner opened this issue Dec 14, 2023 · 0 comments · May be fixed by #17512
Labels
bug mypy got something wrong topic-pep-646 PEP 646 (TypeVarTuple, Unpack)

Comments

@gschaffner
Copy link
Contributor

gschaffner commented Dec 14, 2023

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 gschaffner added the bug mypy got something wrong label Dec 14, 2023
agronholm added a commit to agronholm/anyio that referenced this issue Dec 14, 2023
@ilevkivskyi ilevkivskyi added the topic-pep-646 PEP 646 (TypeVarTuple, Unpack) label Jun 23, 2024
@A5rocks A5rocks linked a pull request Aug 28, 2024 that will close this issue
3 tasks
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-pep-646 PEP 646 (TypeVarTuple, Unpack)
Projects
None yet
2 participants