|
|
|
|
|
by sirclueless
4862 days ago
|
|
Is Python's multiple inheritance model still wonky? For example, I remember this being a "broken" (that is, incompatible with MI) class: class BaseClass:
def __init__(self):
do_important_work()
It's broken, because this class doesn't expect to have any superclass other than Object, and hence doesn't call super(self, BaseClass).__init__(*args, **kwargs)
or something like that (which by the way, is super awkward syntax, repeating both self and BaseClass). But if it's subclassed as one of multiple base classes the parent classes might not get their __init__ methods called (or you might not get your __init__ called, because they forgot to call super().__init__ as well, and the superclass inheritance order ended up putting them in front of you). |
|
In Python 3, you can write just `super()`, even though I personally prefer the verbose (and thus explicit) way.
In single-inheritance cases, there's actually no benefit of using super(), so using `BaseClass.__init__(self, args, *kwargs)` is even more explicit.