Skip to content

Instantly share code, notes, and snippets.

@aj07mm
Forked from motivic/super_multi_inheritance.py
Created February 27, 2018 16:30
Show Gist options
  • Save aj07mm/e269601834bed7a4a4b7a641177c5d74 to your computer and use it in GitHub Desktop.
Save aj07mm/e269601834bed7a4a4b7a641177c5d74 to your computer and use it in GitHub Desktop.
Using super in Python 2.7
# http://stackoverflow.com/questions/222877/how-to-use-super-in-python
class SomeBaseClass(object):
def __init__(self):
print('SomeBaseClass.__init__(self) called')
class ChildClass(SomeBaseClass):
def __init__(self):
print('ChildClass.__init__(self) called')
SomeBaseClass.__init__(self)
class SuperChildClass(SomeBaseClass):
def __init__(self):
print('SuperChildClass.__init__(self) called')
super(SuperChildClass, self).__init__()
class InjectMe(SomeBaseClass):
def __init__(self):
print('InjectMe.__init__(self) called')
super(InjectMe, self).__init__()
# behavior depends on inheritance order
class UnsuperInjector(InjectMe, ChildClass): pass
# class UnsuperInjector(ChildClass, InjectMe): pass
class SuperInjector(InjectMe, SuperChildClass): pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment