cpbotha.net

voices in my head

cpbotha.net random header image

Python new-style object method resolution order

February 28th, 2004 · No Comments · Uncategorized

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. IronPython video demonstration by Jim Hugunin
  4. Parallel Python
  5. Emacs Python folding fixed

Tags:

No Comments so far ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment