Here is the context simplified:
class A(object):
def __init__(self):
self.vocab = [
('method1', self.method1),
('method2', 'arg2', self.method2),
('method3', self.method3),
]
class SubA(A):
def method4(self):
pass
def method5(self, arg5):
pass
class SubB(A):
def method6(self):
pass
def method7(self):
pass
I want to "automatically" fill self.vocab
list from class A with all method from all subclasses and following the rule defined in self.vocab
initialisation. So in this example I want to add method4,...,method7 automatically when object is instanciate.
So self.vocab becomes:
self.vocab = [
('method4', self.method4),
('method5', 'arg5', self.method5),
('method6', self.method6),
('method7', self.method7),
('method1', self.method1),
('method2', 'arg2', self.method2),
('method3', self.method3),
]
I think I have to change A into metaclass and use __new__
instead because I think it must be done before instanciation. In fact the class A is introspected by another code. self.vocab is extracted during instantiation and that's why I think it must be done before.
I don't know how to proceed and if it's possible.