Added callable check

This commit is contained in:
Brandon Rozek 2020-05-21 11:03:01 -04:00
parent 6b750e4c1d
commit 68e4211310

View file

@ -16,6 +16,8 @@ class Application:
def __init__(self): def __init__(self):
self.callbacks = [] self.callbacks = []
def subscribe(self, func): def subscribe(self, func):
if not callable(func):
raise ValueError("Argument func must be callable.")
self.callbacks.append(func) self.callbacks.append(func)
return func return func
def emit(self, message): def emit(self, message):
@ -57,6 +59,8 @@ class Application:
self.callbacks = defaultdict(list) self.callbacks = defaultdict(list)
def on(self, event, func=None): def on(self, event, func=None):
def subscribe(func): def subscribe(func):
if not callable(func):
raise ValueError("Argument func must be callable.")
self.callbacks[event].append(func) self.callbacks[event].append(func)
return func return func
if func is None: if func is None: