Skip to content

Commit

Permalink
Make use of functools.wraps
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaboose committed Jan 27, 2015
1 parent 5d73706 commit 3924421
Showing 1 changed file with 11 additions and 47 deletions.
58 changes: 11 additions & 47 deletions src/owyl/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import logging
from collections import OrderedDict
from functools improt wraps

try:
from mx.Stack import Stack, EmptyError
Expand All @@ -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


Expand All @@ -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


Expand All @@ -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


Expand All @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit 3924421

Please sign in to comment.