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.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.