Skip to content

Instantly share code, notes, and snippets.

@seungha-kim
Created February 28, 2015 13:28
Show Gist options
  • Save seungha-kim/0b579f1af22c5ed83d82 to your computer and use it in GitHub Desktop.
Save seungha-kim/0b579f1af22c5ed83d82 to your computer and use it in GitHub Desktop.
Method resolution order with diamond inheritance
"""
Method resolution order with diamond inheritance
>>> print(Class3.mro())
[Class3, Class1_2, Class1_1, Class2, Class0, <class 'object'>]
"""
class Meta(type):
def __repr__(self):
return self.__name__
class Class0(metaclass=Meta):
pass
class Class1_1(Class0):
pass
class Class1_2(Class1_1):
pass
class Class2(Class0):
pass
class Class3(Class1_2, Class2):
pass
if __name__=="__main__":
import doctest
doctest.testmod()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment