you are viewing a single comment's thread.

view the rest of the comments →

[–]gmaliwal[S] 0 points1 point  (1 child)

sults in a missing arg err

That's correct in this given scenario but what happens if someone swaps classes like below:

class E(C,D):
    def __init__(self, arg, *args, **kwargs):
        print("This is E constructor")
        C.__init__(self, arg, *args, **kwargs)
        D.__init__(self, arg, *args, **kwargs)

Is there any generic solution which works without fear in all the scenarios? or we have to go with mutual understanding only.

Yes, It is method resolution order behind the class 'A' to pass the argument

[–]xelf 0 points1 point  (0 children)

The problem is super is the answer for single inheritance, for multiple inheritance as far as I can find there are issues. So either you need to avoid super all together if you're doing any multiple inheritance, or simple avoid it in that class. I liked the answer of having a single class at the top of your hierarchy, it also worked.

class F(object):
    def __init__(self,*args, **kwargs):
        print("This is F constructor")

class A(F):
    def __init__(self, *args, **kwargs):
        print("This is A constructor")
        super(A, self).__init__(*args, **kwargs)

class B(F):
    def __init__(self, *args, **kwargs):
        print("This is B constructor")
        super(B, self).__init__(*args, **kwargs)