Feb-13-2019, 04:54 PM
(This post was last modified: Feb-13-2019, 05:02 PM by denis_beurive.)
Note:
I find a better way to initialise the parent objects:
However, I can't find a way to use the function "super()" (to perform the same actions).
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".
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".