Demystifying Python's Method Resolution Order

AMiT Kumar (~aktech)


16

Votes

Description:

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

Prerequisites:

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: http://slides.com/aktech/python-mro/
  • [2] Python MRO documentation https://www.python.org/download/releases/2.3/mro/
  • [3] Samuele Pedroni's Mail https://mail.python.org/pipermail/python-dev/2002-October/029035.html

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 http://iamit.in
  • [5] Blog: http://iamit.in/blog/
  • [6] Github: https://github.com/aktech
  • [7] Twitter: https://twitter.com/iaktech
  • [8] Talks: http://iamit.in/talks

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

Thanks for this proposal.

Kushal Das (~kushal)

Login to add a new comment.