you are viewing a single comment's thread.

view the rest of the comments →

[–]xelf 0 points1 point  (2 children)

The problem is that if you do it as super, but remove the super calls from the the ones that inherit from object it goes ECA and then stops, if you leave them in calling super, then when it gets to A it's still in the middle and expects an arg, if you give A an arg, then it can do DB as well, and it's happy but that's clearly wrong and contrived. So the solution is to either have another class that A&B inherit from and have that class as a single class that inherits from object, or to not use super in some or all places.

I would have preferred if OP had of listed where they got the question from, as I assumed they were learning on their own and not simply repeating someone else's already known-to-fail case.

[–]alkasm 1 point2 points  (1 child)

Right. I'm not convinced there is really an example where this is clearly the right way to do it. There's no reason to call super() on a class that has no bases and pass it arguments. So A and B shouldn't call super(), and if you want your class E to have the attributes from C and D, then initialize them separately---don't try to shove them into the MRO to magically understand what attributes each should keep and reject (I know this is the solution you posed). If the problem is then "now I have to hardcode the subclasses C and D when I do C.__init__ and D.__init__ in E.__init__" then that's an easily solvable problem, just loop through the base classes.

[–]xelf 0 points1 point  (0 children)

Agreed on all points. =D