[Python-ideas] Decorations

Daniel Stutzbach daniel at stutzbachenterprises.com
Mon Jul 13 18:48:02 CEST 2009


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/4e3f28c8/attachment.html>


More information about the Python-ideas mailing list