decorating a function and adding functionalities preserving the number of argument
- by pygabriel
I'd like to decorate a function, using a pattern like this:
def deco(func):
def wrap(*a,**kw):
print "do something"
return func(*a,**kw)
return wrap
The problem is that if the function decorated has a prototype like that:
def function(a,b,c): return
When decorated, the prototype is destroyed by the varargs, for example, calling function(1,2,3,4) wouldn't result in an exception. Is that a way to avoid that?
How can define the wrap function with the same prototype as the decorated (func) one?
There's something conceptually wrong?