Scope of decorator argument
Gregor Horvath
gh at gregor-horvath.com
Tue Oct 17 02:34:38 EDT 2006
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 ?
--
Servus, Gregor
More information about the Python-list
mailing list