In Python, we have a simple type of multiple inheritances which allows the creation of mixins. mixins are classes that are used to "mix in" extra properties and methods into a class. This property of mixin allows you to create classes in a compositional style.
An example that illustrates the use of mixin:-
class Mixin1(object):
def test(self):
print ("Mixin1")
class Mixin2(object):
def test(self):
print ("Mixin2")
class MyClass(BaseClass, Mixin1, Mixin2):
pass
In Python, the class hierarchy is defined right to left, so in this case, the Mixin2 class is the base class, extended by Mixin1 class and finally by BaseClass. It is fine because many times the mixin classes don't override each other's, or the base class' methods. In your mixin class, this can lead to unexpected results if you override methods or properties because the priority of how methods are resolved is from left to right.
obj = MyClass()
obj.test()
So the correct way to use mixins is to use as we do in the reverse order which is as follows:
class MyClass(Mixin2, Mixin1, BaseClass):
pass