Python Forum
Multiple inheritance - the right way ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple inheritance - the right way ?
#3
Note:

I find a better way to initialise the parent objects:

        # This is OK:
        # Parent1.__init__(self, *args, **kwargs)
        # Parent2.__init__(self, *args, **kwargs)

        for parent in __class__.__bases__:
            parent.__init__(self, *args, **kwargs)
This strategy is better because the parents classes are not hard-coded.

However, I can't find a way to use the function "super()" (to perform the same actions).

(Feb-13-2019, 04:34 PM)ichabod801 Wrote: Why are you messing with __new__? I would leave that alone. In 15 years of Python programming I have never once needed to mess with __new__. You should be able to do everything with __init__.

You should just need one call to super in each __init__. But you don't go all the way up to object. If you are trying to do a diamond style MRO, you should start with your own base class at the top of the diamond, so you can control the parameters. Then you can have super in all three of the derived classes, and super will follow the MRO through the supers.

Yes, I agree with you. As I said, I don't see any good reason to pass parameters to the constructors. Since it's what initializers are there for.

However, I was exploring multiple inheritance and I wondered : if we can do it, there must be a use for it. Or maybe this is a "legacy thing".
Reply


Messages In This Thread
RE: Multiple inheritance - the right way ? - by denis_beurive - Feb-13-2019, 04:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Multiple Inheritance - Help pls! magnusbrigido 1 1,873 May-17-2019, 12:56 PM
Last Post: ichabod801
  Multiple Inheritance using super() Sagar 2 7,349 Sep-08-2017, 08:58 AM
Last Post: Sagar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020