Your decorator is not necessary. The only thing the decorator does that can't be done with the standard syntax is prevent keyword args from absorbing positional arguments. Thus
class Base(object):
def __init__(name=None,surname=None,age=None):
#some code
class Child(Base):
def __init__(test=None,**kwargs):
Base.__init__(self,**kwargs)
The advantage of this is that kwargs
in Child
will not contain test
. The problem is that you can muck it up with a call like c = Child('red herring')
. This is fixed in python 3.0.
The problem with your approach is that you're trying to use a decorator to do a macro's job, which is unpythonic. The only thing that will get you what you want is something that modifies the locals of the innermost function (f
in your code, specifically the kwargs
variable). How should your decorator know the wrapper's insides, how would it know that it calls a superclass?
David Berger
2009-09-18 20:26:48