Commit 282ab2d6 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

chained _FileOrThing decorators construct output correctly

parent f011b82f
......@@ -176,7 +176,17 @@ def required(*reqargs):
for reqarg in reqargs:
assert reqarg in kwargs
return func(**kwargs)
return _update_wrapper(wrapper, func)
wrapper = _update_wrapper(wrapper, func)
# If this is a bound method, make
# sure that the instance is set on
# the wrapper function - this is
# needed by _FileOrThing decorators.
if hasattr(func, '__self__'):
wrapper.__self__ = func.__self__
return wrapper
return decorator
......@@ -320,25 +330,28 @@ class _FileOrThing(object):
def __call__(self, func):
"""Creates and returns the real decorator function. """
self.__func = func
self.__isFileOrThing = False
isFOT = isinstance(getattr(func, '__self__', None), _FileOrThing)
wrapper = functools.partial(self.__wrapper, func, isFOT)
if hasattr(func, '__self__'):
self.__isFileOrThing = isinstance(func.__self__, _FileOrThing)
wrapper = _update_wrapper(wrapper, func)
wrapper.__self__ = self
wrapper = functools.partial(self.__wrapper, func)
return wrapper
return _update_wrapper(wrapper, func)
def __wrapper(self, func, *args, **kwargs):
def __wrapper(self, func, isFileOrThing, *args, **kwargs):
"""Function which wraps ``func``, ensuring that any arguments of
type ``Thing`` are saved to temporary files, and any arguments
with the value :data:`RETURN` are loaded and returned.
func = self.__func
isFileOrThing = self.__isFileOrThing
:arg func: The func being wrapped.
:arg isFileOrThing: Set to ``True`` if ``func`` is a wrapper metho
of another ``_FileOrThing`` instance. In this case,
the output arguments will be flattenedinto a single
kwargs = kwargs.copy()
kwargs.update(argsToKwargs(func, args))
......@@ -372,7 +385,7 @@ class _FileOrThing(object):
if isFileOrThing:
things = result[1:]
result = result[0]
return tuple([result] + things + outthings)
return tuple([result] + list(things) + outthings)
return tuple([result] + outthings)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment