[Python-ideas] Decorations

Andrey Fedorov anfedorov at gmail.com
Mon Jul 13 19:39:23 CEST 2009


Thanks for the pointer. One thing the decorator library doesn't solve is
abstracting the boiler of decorators that take parameters (and making it
simple to switch between "parametrized" decorators, "naked" decorators, and
"mixed" decorators). Although it's certainly worth giving some thought to
and re-considering some of my internals.

Cheers,
Andrey

On Mon, Jul 13, 2009 at 12:48 PM, Daniel Stutzbach <
daniel at stutzbachenterprises.com> wrote:

> On Mon, Jul 13, 2009 at 11:36 AM, Andrey Fedorov <anfedorov at gmail.com>wrote:
>
>> It seems to me everything but line 5 "assert..." is cruft. In my mind, it
>> makes sense to call that line the "decoration" (part of the decorator).
>> Since it's a decoration that's executed after the decorated function, it
>> makes sense to call it a post-decoration, one that may be more nicely
>> defined as:
>>
>> @postdecoration
>> def returns(result, rtype):
>>     assert isinstance(result, rtype), "return value %r does not match %s"
>> % (result, rtype)
>>
>>
> You might be interested in the decorator module, which similarly tries to
> reduce the amount of boiler-plate code needed to build a decorator:
>
> http://pypi.python.org/pypi/decorator
>
> (though it does not address exactly the same use case that you are
> addressing)
>
> --
> 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/20090713/8bdf31ea/attachment.html>


More information about the Python-ideas mailing list