diff --git a/src/owyl/core.py b/src/owyl/core.py index 9b4a027..0c494fb 100644 --- a/src/owyl/core.py +++ b/src/owyl/core.py @@ -14,6 +14,7 @@ import logging from collections import OrderedDict +from functools improt wraps try: from mx.Stack import Stack, EmptyError @@ -33,19 +34,12 @@ def wrap(func, *args, **kwargs): """Wrap a callable as a task. Yield the boolean of its result. """ + @wraps(func) def initTask(**initkwargs): + @wraps(func) def makeIterator(**runkwargs): result = func(*args, **kwargs) yield bool(result) - try: makeIterator.__name__ = func.__name__ - except AttributeError: pass - try: makeIterator.__doc__ = func.__doc__ - except AttributeError: pass - return makeIterator - try: initTask.__doc__ = func.__doc__ - except AttributeError: pass - try: initTask.__name__ = func.__name__ - except AttributeError: pass return initTask @@ -55,20 +49,13 @@ def task(func): Decorate a generator function to produce a re-usable generator factory for the given task. """ + @wraps(func) def initTask(**initkwargs): + @wraps(func) def makeIterator(**runkwargs): runkwargs.update(initkwargs) iterator = func(**runkwargs) return iterator - try: makeIterator.__name__ = func.__name__ - except AttributeError: pass - try: makeIterator.__doc__ = func.__doc__ - except AttributeError: pass - return makeIterator - try: initTask.__doc__ = func.__doc__ - except AttributeError: pass - try: initTask.__name__ = func.__name__ - except AttributeError: pass return initTask @@ -78,20 +65,13 @@ def taskmethod(func): Decorate a generator function to produce a re-usable generator factory for the given task. """ + @wraps(func) def initTask(self, **initkwargs): + @wraps(func) def makeIterator(**runkwargs): runkwargs.update(initkwargs) iterator = func(self, **runkwargs) return iterator - try: makeIterator.__name__ = func.__name__ - except AttributeError: pass - try: makeIterator.__doc__ = func.__doc__ - except AttributeError: pass - return makeIterator - try: initTask.__doc__ = func.__doc__ - except AttributeError: pass - try: initTask.__name__ = func.__name__ - except AttributeError: pass return initTask @@ -103,21 +83,13 @@ def parent_task(func): Decorate a generator function to produce a re-usable generator factory for the given task. """ + @wraps(func) def initTask(*children, **initkwargs): + @wraps(func) def makeIterator(**runkwargs): runkwargs.update(initkwargs) iterator = func(*children, **runkwargs) return iterator - try: makeIterator.__name__ = func.__name__ - except AttributeError: pass - try: makeIterator.__doc__ = func.__doc__ - except AttributeError: pass - return makeIterator - try: initTask.__doc__ = func.__doc__ - except AttributeError: pass - try: initTask.__name__ = func.__name__ - except AttributeError: pass - return initTask def parent_taskmethod(func): @@ -128,21 +100,13 @@ def parent_taskmethod(func): Decorate a generator function to produce a re-usable generator factory for the given task. """ + @wraps(func) def initTask(self, *children, **initkwargs): + @wraps(func) def makeIterator(**runkwargs): runkwargs.update(initkwargs) iterator = func(self, *children, **runkwargs) return iterator - try: makeIterator.__name__ = func.__name__ - except AttributeError: pass - try: makeIterator.__doc__ = func.__doc__ - except AttributeError: pass - return makeIterator - try: initTask.__doc__ = func.__doc__ - except AttributeError: pass - try: initTask.__name__ = func.__name__ - except AttributeError: pass - return initTask def visit(tree, **kwargs):