Created
March 24, 2014 07:45
-
-
Save Nagasaki45/9735804 to your computer and use it in GitHub Desktop.
Another try to understand python MRO. Depth first?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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