Skip to content

Instantly share code, notes, and snippets.

@Nagasaki45
Created March 24, 2014 07:45
Show Gist options
  • Save Nagasaki45/9735804 to your computer and use it in GitHub Desktop.
Save Nagasaki45/9735804 to your computer and use it in GitHub Desktop.
Another try to understand python MRO. Depth first?
class A1(object):
def __init__(self):
print('A1>')
super(A1, self).__init__()
class B1(A1):
def __init__(self):
print('B1>')
super(B1, self).__init__()
class A2(object):
def __init__(self):
print('A2>')
super(A2, self).__init__()
class B2(A2):
def __init__(self):
print('B2>')
super(B2, self).__init__()
class Final(B1, B2):
def __init__(self):
print('Final>')
super(Final, self).__init__()
f = Final()
# print: Final > B1 > A1 > B2 > A2
# if the resolution order isn't depth first the MRO should print
# Final > B1 > B2 > A1 > A2
# ???
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment