Demystifying Python's Method Resolution Order

AMiT Kumar (~aktech)




This talk is based on the method resolution order which defines the "class search path" used by Python to search for the right method to use in classes having multi-inheritance.

Brief Background: It all started with a post by Samuele Pedroni to the Python development mailing list on 1 Oct 2002. In his post, Samuele showed that the Python 2.2 method resolution order is not monotonic and he proposed to replace it with the C3 method resolution order. Guido agreed with his arguments and therefore now Python 2.3 uses C3.

Hence, Python uses two algorithms for method resolution order. The Old MRO algorithm is very straight forward but the new one is not so easy to bring out. I will be discussing and explaining both the algorithm and I would also be talking a a bit about the background of this change and the benefits of new C3 Method Resolution Order.

Talk Outline:

  • The Problem (Why we need MRO)
  • Solution : (The two Algorithms)
  • Old classes and New classes
  • The old MRO Algorithm
  • Inconsistency with Old MRO
  • Examples of finding MRO using old algorithm
  • Linearization of a Class (some terms for new algorithm)
  • C3 Method Resolution Order (The New MRO)
  • The new MRO Algorithm
  • Examples of working of new MRO algorithm
  • Why its better?
  • Concluding notes


There are no prerequisites for this talk, anyone who can write a class in python and have a basic idea of inheritance can easily follow this talk.

Content URLs:

  • [1] Slides:
  • [2] Python MRO documentation
  • [3] Samuele Pedroni's Mail

Speaker Info:

Amit Kumar is a Core Developer at SymPy. He also participated in Google Summer of Code 2015 under Python Software Foundation to work on the Solvers module of SymPy. Currently he is mentoring SymPy GSoC Students and helping new developers to contribute to SymPy & Open Source and also conducts workshops for Scientific Computing with Python using SymPy. He has assisted a workshop at PyCon India 2015 & spoken at FOSSASIA Singapore and PyDelhi Meetups. He is also co-speaker for SymPy Tutorial at SciPy 2016, US He is a member of Python Delhi User group.

Speaker Links:

Amit Kumar | Links

  • [4] Website
  • [5] Blog:
  • [6] Github:
  • [7] Twitter:
  • [8] Talks:

Section: Core Python
Type: Talks
Target Audience: Beginner
Last Updated: