Python new-style object method resolution order

Caveat emptor! Due to the diamond-like inheritance structures frequently seen with new-style Python objects (i.e. all objects are derived from the “object” class), the Python method resolution order (MRO) has been slightly adapted.

It used to be left-to-right, depth first. With old-style objects, this almost never caused problems. With new-style, because of the common “object” ancestor, this could cause redundant occurrences (obviously due to the diamond structure). Typically Python, this has been solved in a simple yet effective manner.

When trying to determine which method will be invoked when working with multiply-inherited (or mixed-in) objects, use the left-to-right depth first rule. However, if you see any repeated occurrences, delete all but the last. This is the new Python MRO.

Oh bugger, just read this.

Related posts:

  1. Python new-style objects and __slots__
  2. Python IDE wanted, good, cheap and fast. :)
  3. Python 2.6 enabled VTK 5.4 Windows binaries
  4. IronPython video demonstration by Jim Hugunin
  5. Emacs Python folding fixed

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>