[Python-ideas] @return?

Daniel Stutzbach daniel at stutzbachenterprises.com
Wed Apr 14 00:41:53 CEST 2010


On Tue, Apr 13, 2010 at 4:36 PM, Conrad Irwin
<conrad.irwin at googlemail.com>wrote:

> A common pattern when creating decorators is something of the form:
>
>    def decorator(func):
>        def wrapper(*args):
>            func(modulate(args))
>        return wrapper
>

You might be interested in Michele Simionato's excellent decorator package.
The above could be written:

import decorator
def my_decorator(func):
    return decorator.decorator(func, lambda: func(modulate(args)))

If your pattern is very common, you could even create your own
meta-decorator, like this:

def args_modulator(func, modulator):
    return decorator.decorator(func, lambda: func(modulator(args)))

It's available on PyPi:  http://pypi.python.org/pypi/decorator

In a nutshell, whatever part of your pattern is common, abstract out.
--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100413/2ba3b2f7/attachment.html>


More information about the Python-ideas mailing list