You can access the pre-decorated function:
wrapped_func.func_closure[0].cell_contents()
For instance,
def decorator_function(func): def wrapper(*args, **kwargs): print('Bar') return func(*args, **kwargs) return wrapper @decorator_function def wrapped_func(): print('Foo') wrapped_func.func_closure[0].cell_contents()
prints
Foo
But really, if you know you want to access a pre-decorated function, then it would be much easier to define
def wrapped_func(): print('Foo') deco_wrapped_func = decorator_function(wrapped_func)
So wrapped_func will be a pre-decorated function, and deco_wrapped_func will be a decorated version.
source share