Mentions légales du service

Skip to content
Snippets Groups Projects
Commit ec0ca3ef authored by PEDERSEN Ny Aina's avatar PEDERSEN Ny Aina
Browse files

events: move arity check to runtime

We cannot add attributes to a method, and I do not want to wrap the
callback function or to modify the callback function set, so I
moved the check to the runtime. It should not change the performance.
parent 3ad61994
No related branches found
No related tags found
No related merge requests found
......@@ -30,17 +30,11 @@ class EventList:
:param event: The name of the event to listen.
:param function: The function to call on update.
If the function arity is 2, then on update,
it will be called with the variable name and its
new value. If the function arity is 1, it will be
called with the updated value.
If the function arity is 2, then on update,
it will be called with the variable name and its
new value. If the function arity is 1, it will be
called with the updated value.
"""
# Checking the function arity
arity = len(signature(function).parameters)
if arity not in [1, 2]:
raise Exception(f"Wrong arity for event callback funtion {function.__name__}")
function._arity = arity
self.events[event].add(function)
def disconnect(
......@@ -67,7 +61,11 @@ class EventList:
"""
for variable in variable_list:
for function in self.events[f"value_change:{variable}"]:
if function._arity == 1:
# Checking the function arity
arity = len(signature(function).parameters)
if arity not in [1, 2]:
raise RuntimeError(f"Wrong arity for event callback funtion {function.__name__}")
if arity == 1:
function(self.variables[variable])
else:
function(variable, self.variables[variable])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment