Search notes:

Python: __mro__

__mro__ stands for method resolution order. It is a tuple whose elements correspond to the types from which a type is derived (and hence, this dunder is found in type objects).
class A: pass
class B: pass

class C(A, B): pass

print(A.__mro__)
#
#  (<class '__main__.A'>, <class 'object'>)

print(B.__mro__)
#
#  (<class '__main__.B'>, <class 'object'>)

print(C.__mro__)
#
#  (<class '__main__.C'>, <class '__main__.A'>, <class '__main__.B'>, <class 'object'>)

a = A()
b = B()
c = C()

assert not hasattr(a, '__mro__')
assert not hasattr(b, '__mro__')
assert not hasattr(c, '__mro__')
Github repository about-Python, path: /dunders/__mro__/demo.py

See also

multiple inheritance
The built-in function type().
Other dunders (such as __bases__ which returns a class's immediate super classes).

Index