TypeVarTuple with Callable and default arguments
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 1.8k
- Forks
- 302
- Ø Merge
- 23 Std.
- Gemergte PRs (30 T.)
- 8
Beschreibung
Previous discussion: https://github.com/microsoft/pyright/issues/3775
I've been playing around with TypeVarTuples recently, in particular together with Callable and args.
https://peps.python.org/pep-0646/#type-variable-tuples-with-callable
One issue became obvious early on which isn't defined in the PEP itself.
How should default arguments be handled?
A common pattern, especially in async code, is to pass a callable and it's args to a function
from typing import Callable
from typing_extensions import TypeVarTuple
Ts = TypeVarTuple("Ts")
def call_later(cb: Callable[[*Ts], None], *args: *Ts) -> None: ...
That works well if all arguments are required
def func1(x: int, y: int, z: int) -> None: ...
call_later(func1, 0, 0, 0) # ok
However, what should happen if y and z have default arguments?
def func2(x: int, y: int = 0, z: int = 0) -> None: ...
call_later(func2, 0)
Instinctively, I would think that it should work, too. As @erictraut did point out though, there are at least a few cases where the behavior would need to be further specified / or explicitly forbidden.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
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 mit dem Lesen der vorherigen Diskussion in issue 3775 und des PEP-646-Abschnitts zu TypeVarTuples mit Callable. Vergleiche die Beispiele für erforderliche Argumente und Standardargumente sowie die in der Diskussion aufgeworfenen Randfälle und lege ein spezifiziertes oder ausdrücklich verbotenes Verhalten für Standardargumente fest.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100