How to access decorator from base class in child?
I assumed (erroneously) that ffg. will work:
class baseclass(object):
def __init__(self):
print 'hey this is the base'
def _deco(func):
def wrapper(*arg):
res = func(*arg)
print 'I\'m a decorator. This is fabulous, but that colour, so last season sweetiedarling'
return res
return wrapper
@_deco
def basefunc(self):
print 'I\'m a base function'
This class works fine, but then I create a child class that inherits from this:
class otherclass(baseclass):
def __init__(self):
super(otherclass, self).__init__()
print 'other class'
@_deco
def meh(self):
print 'I\'m a function'
It will not even be correctly imported, not to mention the launch. @_deco - undefined. An attempt by baseclass._deco throws an unbound method _deco () error, which is not surprising.
Any idea how to do this, I would really like to encapsulate the decorator in the class, but I am not married to this idea, and I would have to name it in the base and child class.
source
share