From e9d71e925158ebe936aff4f2324a6f66978e82b4 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Sat, 3 Mar 2018 15:41:14 +0000 Subject: [PATCH] Small refactor to _FileOrThing to iron out some bugs --- fsl/wrappers/wrapperutils.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/fsl/wrappers/wrapperutils.py b/fsl/wrappers/wrapperutils.py index 4ced92099..bac9cc33c 100644 --- a/fsl/wrappers/wrapperutils.py +++ b/fsl/wrappers/wrapperutils.py @@ -456,26 +456,21 @@ class _FileOrThing(object): self.__func = None - def __call__(self, func): + def __call__(self, *args, **kwargs): """Creates and returns the decorated function. """ - self.__func = func + # the first call will be our decorated + # function getting passed in. + if self.__func is None: + func = args[0] + self.__func = func + return self - # Wrap the wrapper because update_wrapper - # will raise an error if we pass it - # self.__wrapper. This is because it is - # not possible to set attributes on bound - # methods. - def wrapper(*args, **kwargs): + # Subsequent calls will be calls + # to the decorated function. + else: return self.__wrapper(*args, **kwargs) - # We replace this __call__ method - # with the decorated function, so - # this instance is the decorator, - # and __get__ will work as intended. - self.__call__ = _update_wrapper(wrapper, func) - return self - def __get__(self, instance, owner): """Called when this ``_FileOrThing`` has been used to decorate a method -- GitLab