Callables like `operator.call` produce `arg-type` error with callables that take `*args: Unpack[Ts]` and >= 1 keyword argument
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia eseguendo il riproduttore fornito con mypy sul master corrente e confronta il comportamento con l’issue #16405. Traccia la gestione dei callable di operator.call, ParamSpec e TypeVarTuple; il lavoro è completato quando la chiamata con argomenti denominati non produce alcun errore arg-type e i controlli esistenti rimangono corretti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100