On 10/10/2013 11:13 PM, Cameron Simpson wrote:
On 11Oct2013 02:55, Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info>
wrote:
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.)
It only works if the decorator returns a closure with the original
function as the first member (of func_closure). Often true, but not at
all a requirement.
--
Terry Jan Reedy
--
https://mail.python.org/mailman/listinfo/python-list