Type Methods

type.mro()

Compute the method resolution order of a class. For ordinary classes, the default C3 linearization places the class first and merges its bases consistently with their local precedence and existing MROs; a shared base appears only once. Attribute lookup and cooperative super() use the stored order in __mro__. A metaclass can override mro() during class creation, so calling a custom mro() later is not necessarily the same as reading the stored tuple. An inconsistent hierarchy raises TypeError at class creation.

Formal Syntax & Structure

python syntaxpython
Class.mro()type.mro(Class, /)

Return Value

list[type]

List of classes in the default computed lookup order.

Working Example

Example Snippetpython
class Root: passclass Left(Root): passclass Right(Root): passclass Leaf(Left, Right): passprint([cls.__name__ for cls in Leaf.mro()])print(tuple(Leaf.mro()) == Leaf.__mro__)
Python Reference