Skip to content

Instantly share code, notes, and snippets.

@AdamSpannbauer
Created January 25, 2019 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamSpannbauer/269dc8ded25238926979f7ab9867d719 to your computer and use it in GitHub Desktop.
Save AdamSpannbauer/269dc8ded25238926979f7ab9867d719 to your computer and use it in GitHub Desktop.
demonstrating diamond problem stuff with super in python
class A:
def x(self):
print('x: A')
class B(A):
def x(self):
super().x()
print('x: B')
def y(self):
print('y: B')
def z(self):
print('z: B')
class C(A):
def x(self):
super().x()
print('x: C')
def y(self):
print('y: C')
def z(self):
print('z: C')
class D(C, B):
def z(self):
super().z()
print('z: D')
d = D()
d.x()
d.y()
d.z()
print(D.mro())
@AdamSpannbauer
Copy link
Author

Output:

x: A
x: B
x: C
y: C
z: C
z: D
[<class '__main__.D'>, <class '__main__.C'>, <class '__main__.B'>, <class '__main__.A'>, <class 'object'>]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment