New to python here and I am looking to attach some class, ClassA.methodA to another ClassB as below
def methodA(self, x=None, y=None, z='somevalue', l=None, m=False, **kwds):
... Some logic here....
a = self.getMyInstanceOfClassA() //a is of type ClassA, not ClassB
a.methodA(x,y,z,l,m,**kwds)
ClassB.methodA = methodA
...
h = ClassB()
h.methodA("p1", "p2", m=True)
The goal is to keep the signature of ClassB.methodA the same as it is supposed to be on the actual ClassA.methodA which is accessible on ClassB.getMyInstanceOfClassA()
method.
The reason I am doing this is to avoid my user to write this code
h = ClassB()
---the extra logic---
a = h.getMyInstanceOfClassA()
a.methodA(....)
an instead just say
h = ClassB()
h.methodA(....)
and I embed the extra logic inside the new methodA on ClassB.
methodA is something meaningful in our domain and I have to keep its name and exact signature
I have to import both ClassA and ClassB from our internal libs and I can't make ClassB inherit from ClassA.
The point is that methodA is usually not called with all of its arguments and the arguments passed depends on what you want methodA to do. This h.methodA("p1", "p2", m=True)
fails with some error complaining about passing too many argument to it.
Am I wrapping the methodA correctly?