I have a mix-in class called WithAutoNumbering for classes that need a special numbering of a given attribute. Appart from that I have a nice class mix-in called WithIndexing for those classes that need indexing capabilities... which needs the capabilities of WithAutoNumbering.
Some classes need numbering but not indexing, so mixing them together is not a good idea.
The dilemma is, should WithIndexing inherit from WithAutoNumbering? or each class that needs WithIndexing should also inherit from WithAutoNumbering as well?
I.e. this, with CoolClass being the one that has to implement indexing:
class WithAutoNumbering(object):
...
class WithIndexing(WithAutoNumbering):
...
class CoolClass(WithIndexing):
...
or this
class WithAutoNumbering(object):
...
class WithIndexing(object):
...
class CoolClass(WithIndexing, WithAutoNumbering):
...
On the one hand, the first approach is more succint, and makes sure that you can't try to use WithIndexing withouth WithAutoNumbering. On the other hand, I have always read (and found it agreeable) that mix-ins should not have hierarchy, i.e. inherit only from object, in order to avoid spaghettization of the whole class hierarchy with ununderstandable __mro__s