python / python/typing_extensions
TypeError: Parameter list cannot be empty for TypeVarTuple
Offen
Dieses Issue hat noch niemand übernommen.
pep-646
- Vorherrschende Sprache
- Python
- Sterne
- 583
- Forks
- 146
- Ø Merge
- 10 Std. 11 Min.
- Gemergte PRs (30 T.)
- 5
Beschreibung
There is a problem with typing_extensions that doesn't happen with typing. Running the program with python3.11 works, but with python3.10 with typing_extensions throws:
Traceback (most recent call last):
File ".../main.py", line 48, in <module>
main()
File ".../main.py", line 40, in main
signal: Signal[()] = Signal[()]()
File "/usr/lib/python3.10/typing.py", line 312, in inner
return func(*args, **kwds)
File "/usr/lib/python3.10/typing.py", line 1328, in __class_getitem__
raise TypeError(
TypeError: Parameter list to Signal[...] cannot be empty
from __future__ import annotations
from typing_extensions import Callable, TypeVarTuple, Generic, Unpack, List, TypeVar
VarArgs = TypeVarTuple('VarArgs')
class Signal(Generic[Unpack[VarArgs]]):
def __init__(self):
self.functions: List[Callable[..., None]] = []
"""
Simple mechanism that allows abstracted invocation of callbacks. Multiple callbacks can be attached to a signal
so that they are all called when the signal is emitted.
"""
def connect(self, function: Callable[..., None]):
"""
Add a callback to this Signal
:param function: callback to call when emited
"""
self.functions.append(function)
def emit(self, *args: Unpack[VarArgs]):
"""
Call all callbacks with the arguments passed
:param args: arguments for the signal, must be the same type as type parameter
"""
for function in self.functions:
if args:
function(*args)
else:
function()
def main():
def signalEmptyCall():
print("Hello!")
signal: Signal[()] = Signal[()]()
signal.connect(signalEmptyCall)
signal.emit()
if __name__ == '__main__':
main()
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 mit der Reproduktion in main.py und vergleiche das Verhalten von Signal[()] unter Python 3.10 mit typing_extensions und Python 3.11 mit typing. Verfolge die Behandlung von TypeVarTuple und leeren Parametern und füge anschließend einen Regressionstest hinzu oder aktualisiere ihn, der zeigt, dass die leere Parameterliste konsistent akzeptiert wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100