Callables like `operator.call` produce `arg-type` error with callables that take `*args: Unpack[Ts]` and >= 1 keyword argument
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, den bereitgestellten Reproducer mit mypy auf dem aktuellen master auszuführen, und vergleiche das Verhalten mit Issue #16405. Verfolge die Behandlung von aufrufbaren Objekten mit operator.call, ParamSpec und TypeVarTuple; als abgeschlossen gilt die Aufgabe, wenn der Aufruf mit Schlüsselwortargumenten keinen arg-type-Fehler erzeugt und die bestehenden Prüfungen weiterhin korrekt sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100