Is there a way to set all attributes in a decorated function as in the original function?
For example if I take this code:
def timeit(f):
import time
def new_f(n):
start = time.time()
res = f(n)
end = time.time()
tt = end-start
print tt
return res
return new_f
@timeit
def fun(n=0):
''' docstring '''
res = 0
for _ in xrange(n):
res = res + 1
return res
Then the function fun has actually lost all its attributes such as fun.func_defaults or fun.func_dict or fun.func_doc. Is there a generic way to handle this?