You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypeError: Parameter list cannot be empty for TypeVarTuple #322
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__ importannotationsfromtyping_extensionsimportCallable, TypeVarTuple, Generic, Unpack, List, TypeVarVarArgs=TypeVarTuple('VarArgs')
classSignal(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. """defconnect(self, function: Callable[..., None]):
""" Add a callback to this Signal :param function: callback to call when emited """self.functions.append(function)
defemit(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 """forfunctioninself.functions:
ifargs:
function(*args)
else:
function()
defmain():
defsignalEmptyCall():
print("Hello!")
signal: Signal[()] =Signal[()]()
signal.connect(signalEmptyCall)
signal.emit()
if__name__=='__main__':
main()
ifnotparamsandclsisnotTuple:
raiseTypeError(f"Parameter list to {cls}[...] cannot be empty")
As params is an empty tuple the TypeError is raised. We either need to monkeypatch typing or create a custom version of Generic - as there are multiple is Generic tests in typing I am not sure how easy it is to create a stable alternative version.
Afaik, the only workaround that can be used before 3.11 is to use the equivalent form of () ≡ Unpack[Tuple[()]]:
Activity
Daraan commentedon Dec 15, 2024
I leave a quick comment here.
The problem is that in 3.10 typing.Generic(and earlier?) there is a check:
As
paramsis an empty tuple theTypeErroris raised. We either need to monkeypatchtypingor create a custom version ofGeneric- as there are multipleis Generictests in typing I am not sure how easy it is to create a stable alternative version.Afaik, the only workaround that can be used before 3.11 is to use the equivalent form of
()≡Unpack[Tuple[()]]:JelleZijlstra commentedon Dec 16, 2024
We could make a
typing_extensions.Genericthat is different fromtyping.Genericand fixes this issue.