G
Gregor Horvath
Hi,
this:
class base(object):
@adecorator(xy)
def edit(self):
print "edit"
class child(base):
xy = 3
obviously fails because "xy" is not bound at class creation time of the
base object.
One solution could be delegation:
class base(object):
@classmethod
def edit(self):
print "do the real work here"
class child(object):
xy = 3
mybase = base
@adecorator(xy)
def edit(self, *args, **kwargs):
self.mybase.edit(*args, **kwargs)
But then I have the ugly boiler plate delegation code in child.
Is there any other solution, probably with metaclasses ?
this:
class base(object):
@adecorator(xy)
def edit(self):
print "edit"
class child(base):
xy = 3
obviously fails because "xy" is not bound at class creation time of the
base object.
One solution could be delegation:
class base(object):
@classmethod
def edit(self):
print "do the real work here"
class child(object):
xy = 3
mybase = base
@adecorator(xy)
def edit(self, *args, **kwargs):
self.mybase.edit(*args, **kwargs)
But then I have the ugly boiler plate delegation code in child.
Is there any other solution, probably with metaclasses ?