Can someone clarify for me why this generates a name error wherein class A cannot find the decorator_warehouse variable, even though it is located inside of its parent class, Mixin?
NameError: name 'decorator_warehouse' is not defined
Also, how can I get the desired functionality which is to house the decorator_warehouse inside of a different class than the class which holds the function I wish to decorate.
class DecoratorWarehouse(object):
"""Object hosts a large number of custom decorators"""
def custom_decorator_A(self, func):
def wrapper(*args, **kwargs):
print "doing stuff before call"
res = func(*args, **kwargs)
print "doing stuff after call"
return res
return wrapper
class Mixin(object):
decorator_warehouse = DecoratorWarehouse()
class A(Mixin):
@decorator_warehouse.custom_decorator_A
def doing_stuff(self):
print "Doing some stuff"
a = A()
a.doing_stuff()