[core/events] simplify args/kwargs detection

This commit is contained in:
tobi-wan-kenobi 2020-06-01 11:35:26 +02:00
parent 86fb4c38ea
commit 9cadcee844

View file

@ -3,7 +3,7 @@ __callbacks = {}
def register(event, callback, *args, **kwargs): def register(event, callback, *args, **kwargs):
cb = callback cb = callback
if len(args) + len(kwargs) > 0: if args or kwargs:
cb = lambda: callback(*args, **kwargs) cb = lambda: callback(*args, **kwargs)
__callbacks.setdefault(event, []).append(cb) __callbacks.setdefault(event, []).append(cb)
@ -19,10 +19,10 @@ def trigger(event, *args, **kwargs):
return False return False
for callback in cb: for callback in cb:
if len(args) + len(kwargs) == 0: if args or kwargs:
callback()
else:
callback(*args, **kwargs) callback(*args, **kwargs)
else:
callback()
return True return True