On 11Oct2013 02:55, Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> wrote: > On Fri, 11 Oct 2013 09:12:38 +1100, Cameron Simpson wrote: > > Speaking for myself, I would be include to recast this code: > > > > @absolutize > > def addition(a, b): > > return a + b > > > > into: > > > > def _addition(a, b): > > return a + b > > addition = absolutize(_addition) > > > > Then you can unit test both _addition() and addition(). > > *shudders* > Ew ew ew ew.
Care to provide some technical discourse here? Aside from losing the neat and evocative @decorator syntax, the above is simple and overt. > I would much rather do something like this: > > def undecorate(f): > """Return the undecorated inner function from function f.""" > return f.func_closure[0].cell_contents Whereas this feels like black magic. Is this portable to any decorated function? If so, I'd have hoped it was in the stdlib. If not: black magic. > And in use: > > py> f(100) > 201 > py> undecorate(f)(100) > 200 All lovely, provided you can convince me that undecorate() is robust. (And if you can, I'll certainly be filing it away in my funcutils module for later use.) Cheers, -- Cameron Simpson <c...@zip.com.au> DRM doesn't inconvenience pirates ¿ indeed, over time it trains law-abiding users to become pirates out of sheer frustration. - Charles Stross -- https://mail.python.org/mailman/listinfo/python-list