Skip to content

Instantly share code, notes, and snippets.

@eclecticmiraclecat
Created May 31, 2020 13:25
Show Gist options
  • Save eclecticmiraclecat/71f6747566479c11abd1c0a160eec26a to your computer and use it in GitHub Desktop.
Save eclecticmiraclecat/71f6747566479c11abd1c0a160eec26a to your computer and use it in GitHub Desktop.
>>> class Parent:
... def spam(self):
... print('Parent.spam')
...
>>> class A(Parent):
... def spam(self):
... print('A.spam')
... super().spam()
...
>>> class B(A):
... def spam(self):
... print('B.spam')
... super().spam()
...
>>> class C(Parent):
... def spam(self):
... print('C.spam')
... super().spam()
...
>>> class D(Parent):
... def spam(self):
... print('D.spam')
... super().spam()
...
>>> class E(A, C, D):
... pass
...
>>> e = E()
>>> e.spam()
A.spam
C.spam
D.spam
Parent.spam
>>>
>>>
>>> class F(C, D, A):
... pass
...
>>> f = F()
>>> f.spam()
C.spam
D.spam
A.spam
Parent.spam
>>>
>>> A.__mro__
(<class '__main__.A'>, <class '__main__.Parent'>, <class 'object'>)
>>> B.__mro__
(<class '__main__.B'>, <class '__main__.A'>, <class '__main__.Parent'>, <class 'object'>)
>>> C.__mro__
(<class '__main__.C'>, <class '__main__.Parent'>, <class 'object'>)
>>> E.__mro__
(<class '__main__.E'>, <class '__main__.A'>, <class '__main__.C'>, <class '__main__.D'>, <class '__main__.Parent'>, <class 'object'>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment