Have you ever wanted a decorator that you could apply either straight-out:
@mydec
def myfun(...):
...
or with special arguments:
@mydec(special=foo)
def myfun(...):
...
? Well, decorate it with this metadecorator, and voila.
(I had this idea independently, but it's been done before as decorator_withargs: http://osdir.com/ml/python.ideas/2008-01/msg00048.html. My version is actually useful because it deals with signatures and calling directly.)
As http://www.siafoo.net/article/68 points out, the standard decorator module has too much magic: the "@decorator" decorator expects a wrapping function, not a working decorator. This module fixes that.
- decorator
- decoratordecorator
- metadecorator