class Base(object):
pass
class Inject(Base):
def __init__(self):
super().__init__() # python3
# super(Inject, self).__init__() # python2
pass
class Child(Base):
def __init__(self, user):
super().__init__() # 1 python3 super() lets you avoid referring to the base class explicitly
# super(Child, self).__init() # 2 python2
# Base.__init__(self) # 3 avoid this, it limit you use multiple inheritance
self.user = user
class SuperInjector(Child, Inject):
pass
# if Child() use SuperInjector() # 2 can call Inject()
# if Child() SuperInjector() use # 3 can't call Inject()
# conclusion:Always use super to reference the parent class !!!
# super() issue. In a class hierarchy with single inheritance, super() can be used to refer to parent classes without naming them explicitly, thus making the code more maintainable; support cooperative multiple inheritance in a dynamic execution environment. addr:https://stackoverflow.com/questions/576169/understanding-python-super-with-init-methods
# standard doc on super. difference between 1 and 2. addr:https://stackoverflow.com/questions/222877/what-does-super-do-in-python
# method resolution order(MRO) addr:https://stackoverflow.com/questions/2010692/what-does-mro-do
# difference between 2 and 3. addr:https://stackoverflow.com/questions/222877/what-does-super-do-in-python/33469090#33469090