__mro__ — Intermediate Examples
Method Resolution Order; the order in which base classes are searched
__mro__ with custom classes
Working with __mro__ in your own classes.
python
# Using __mro__ with custom classes class Registry: def __init__(self): self._items = {} def register(self, cls): self._items[cls.__name__] = cls return cls def get(self, name): return self._items.get(name) registry = Registry() @registry.register class Widget: pass @registry.register class Button: pass print(registry._items) print(registry.get("Widget"))
Custom classes interact with __mro__ in specific ways that are useful to understand.
Want to try these examples interactively?
Open Intermediate Playground