From 1c6947b5713eb78d1cacb963134a9cfb0020ed32 Mon Sep 17 00:00:00 2001 From: Jan David Mol <mol@astron.nl> Date: Mon, 25 Jan 2021 10:15:22 +0100 Subject: [PATCH] Fixed use of decorator with arguments --- RCUSCC/RCUSCC/wrappers.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/RCUSCC/RCUSCC/wrappers.py b/RCUSCC/RCUSCC/wrappers.py index cb557c418..14d8f1d64 100644 --- a/RCUSCC/RCUSCC/wrappers.py +++ b/RCUSCC/RCUSCC/wrappers.py @@ -4,20 +4,23 @@ import traceback __all__ = ["only_in_states", "only_when_on", "fault_on_error"] -def only_in_states(func, allowed_states): +def only_in_states(allowed_states): """ Wrapper to call and return the wrapped function if the device is in one of the given states. Otherwise None is returned and nothing will be called. """ - @wraps(func) - def state_check_wrapper(self, *args, **kwargs): - if self.get_state() in allowed_states: - return func(self, *args, **kwargs) + def wrapper(func): + @wraps(func) + def state_check_wrapper(self, *args, **kwargs): + if self.get_state() in allowed_states: + return func(self, *args, **kwargs) - return None + return None + + return state_check_wrapper - return state_check_wrapper + return wrapper def only_when_on(func): """ -- GitLab