github.com/hoffmann Peter Hoffmann on Stackoverflow @peterhoffmann on twitter Peter Hoffmann on Facebook Contact me per email Subscribe to Atom Feed

Peter Hoffmann

Software Engineer
prev page next page

Is there a way to get the function a decorator has wrapped?

Posted on October 9, 2009
#stackoverflow #python

This my Answer to the stackoverflow question: Is there a way to get the function a decorator has wrapped?:

You can attach the wrapped function to the inner function

In [1]: def wrapper(f):
   ...:     def inner():
   ...:         print "inner"
   ...:     inner._orig = f
   ...:     return inner
   ...: 

In [2]: @wrapper
   ...: def foo():
   ...:     print "foo"
   ...:     
   ...:     

In [3]: foo()
inner

In [4]: foo._orig()
foo