When a class subclasses multiple base classes, attribute lookup is performed from left to right amongst the base classes. This form of attribute lookup is called "method resolution order" and is a solution to the diamond inheritance problem where several base classes override a method in a shared superclass.

Unfortunately, this means that if more than one base class defines the same attribute, the leftmost base class will effectively override the attribute of the rightmost base class, even though the leftmost base class is not a subclass of the rightmost base class. Unless the methods in question are designed for inheritance, using super, then this implicit overriding may not be the desired behavior. Even if it is the desired behavior it makes the code hard to understand and maintain.

There are a number of ways that might be used to address this issue:

In this example the class ThreadingTCPServer inherits from ThreadingMixIn and from TCPServer. However, both these classes implement process_request which means that ThreadingTCPServer will inherit process_request from ThreadingMixIn. Consequently, the implementation of process_request in TCPServer will be ignored, which may not be the correct behavior.

This can be fixed either by overriding the method, as shown in class ThreadingTCPServerOverriding or by ensuring that the functionality provided by the two base classes does not overlap, as shown in class ThreadingTCPServerChangedHierarchy.

  • Python Language Reference: Data model.
  • Python releases: The Python 2.3 Method Resolution Order.
  • Wikipedia: C3 linearization.
  • Wikipedia: Composition over inheritance.