First of all I don't know if this is the right approach. I want to write a decorator class that will be used with methods of other class. Before running the method I'd like to check if all required class variables are initialized. The ideal case would be something similar to this:
class Test(object):
def __init__(self, f):
self.f = f
# some magic
def __call__(self):
self.f.magically_get_variable(required)
# do some checks and execute method or throw an exception
class Data(object):
def __init__(self, a, b):
self.a = a
@test
def sum(self):
required('self.a', 'self.b')
return self.a + self.b
If this is not the way it should be done please advise me how to do it properly.