stacked decorators and consolidating

2013-10-29 Thread Tim Chase
I've got some decorators that work fine as such: @dec1(args1) @dec2(args2) @dec3(args3) def myfun(...): pass However, I used that sequence quite a bit, so I figured I could do something like dec_all = dec1(args1)(dec2(args2)(dec3(args3))) to consolidate the whole mess down to

Re: stacked decorators and consolidating

2013-10-29 Thread MRAB
On 29/10/2013 16:54, Tim Chase wrote: I've got some decorators that work fine as such: @dec1(args1) @dec2(args2) @dec3(args3) def myfun(...): pass However, I used that sequence quite a bit, so I figured I could do something like dec_all =

Re: stacked decorators and consolidating

2013-10-29 Thread Peter Otten
Tim Chase wrote: I've got some decorators that work fine as such: @dec1(args1) @dec2(args2) @dec3(args3) def myfun(...): pass However, I used that sequence quite a bit, so I figured I could do something like dec_all = dec1(args1)(dec2(args2)(dec3(args3))) With these

Re: stacked decorators and consolidating

2013-10-29 Thread Tim Chase
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

Re: stacked decorators and consolidating

2013-10-29 Thread Gregory Ewing
Tim Chase wrote: I'd have figured they would be associative, making the result end up the same either way, but apparently not. They're not associative because function application is not associative: f(g(x)) is not the same thing as f(g)(x). -- Greg --