stacked decorators and consolidating
Tim Chase
python.list at tim.thechases.com
Tue Oct 29 13:54:05 EDT 2013
On 2013-10-29 17:42, MRAB wrote:
> If you apply the stacked decorators you get:
>
> myfun = dec1(args1)(dec2(args2)(dec3(args3)(myfun)))
>
> If you apply dec_all you get:
>
> myfun = dec1(args1)(dec2(args2)(dec3(args3)))(myfun)
>
> See the difference? You need the lambda to fix that.
In this case, they happen to be CherryPy decorators:
@cherrypy.expose()
@cherrypy.tools.json_in()
@cherrypy.tools.json_out()
def myfunc(...): pass
I'd have figured they would be associative, making the result end up
the same either way, but apparently not. Thanks for helping shed
some light on the subtle difference.
-tkc
More information about the Python-list
mailing list