I would like to decorate a function using a template similar to this:
def deco(func):
def wrap(*a,**kw):
print "do something"
return func(*a,**kw)
return wrap
The problem is that if the decorated function has a prototype like this:
def function(a,b,c): return
When decorating, the prototype is destroyed by varargs, for example, the calling function (1,2,3,4) will not lead to an exception. Is this a way to avoid this? How to define a wrapping function with the same prototype as decorated (func)?
Is there something conceptually wrong?
EDIT
My perverted idea was to make it easier to “call the parent method” without changing the signature. Sort of
def __init__(self, something)
super(ClassName, self).__init__(something)
at
@extended
def __init__(self, something):
...
I figured out if this is possible, and if that makes sense.
EDIT As Alex noted, the following code does not throw an exception:
function(1,2,3,4)
source
share