In A.__init__ I call self.func(argument):
class A(object): def __init__(self, argument, key=0): self.func(argument) def func(self, argument): #some code here I want to change the signature of A.func in B. B.func gets called in B.__init__ through A.__init__:
class B(A): def __init__(self, argument1, argument2, key=0): super(B, self).__init__(argument1, key) # calls A.__init__ def func(self, argument1, argument2): #some code here Clearly, this doesn't work because the signature of B.func expects two arguments while A.__init__ calls it with one argument. How do I work around this? Or is there something incorrect with the way I have designed my classes?
key is a default argument to A.__init__. argument2 is not intended for key. argument2 is an extra argument that B takes but A does not. B also takes key and has default value for it.
Another constraint is that I would like not to change the signature of A.__init__. key will usually be 0. So I want to allow users to be able to write A(arg) rather than A(arg, key=0).
argument2?__init__that are meant to be overridden is dangerous, since those methods may depend on subclass initialization that hasn't happened yet.argument1andargument2to be passed on toB.func()whensuper(B, self).__init__(argument1, argument2)is called? What is the role ofkey=0inA.__init__()in this respect, should it capture the value ofargument2at all?