| I think multiple inheritance will always scare me. What order do the superclass inits run in? What happens if they do conflicting things? What if some superclasses call super().__init__ and others don't? No thanks, I'll suffer through reading a few additional lines of: class SomeBusinessyThing: def __init__(self, util, other_util):
self._util = util
self._other_util = other_util
@classmethod
def create(cls):
return cls(util_module.Util(), other_module.Other())
def calculate(self):
source = self_other_util.get_source()
return self._util.get_stuff(source)
vsclass SomeBusinessyThing(Utils, Other): def __init__(self, \*kwargs):
# What does this do? No one knows
super().__init__(self, \*kwargs)
def calculate(self):
source = self.get_source()
return self.get_stuff(source)
|
Using multiple inheritance to implement certain common functionality, using mixin classes, is possible in Python; it's another powerful tool in the arsenal, but doesn't mean that you have to use it.
Inheritance works best to denote "is-a" relationships, i.e. for defining subtypes, especially when using type annotations and checks. Sometimes - albeit very rarely - you need a class that belongs to two separate type hierarchies; multiple inheritance comes very handy in those cases.