How does the order of mixins affect the derived class?

The MRO is basically depth-first, left-to-right. See Method Resolution Order (MRO) in new style Python classes for some more info. You can look at the __mro__ attribute of the class to check, but FooMixin should be first if you want to do “check A” first. class UltimateBase(object): def dispatch(self, *args, **kwargs): print ‘base dispatch’ class … Read more

TypeError: Cannot create a consistent method resolution order (MRO) [duplicate]

Your GameObject is inheriting from Player and Enemy. Because Enemy already inherits from Player Python now cannot determine what class to look methods up on first; either Player, or on Enemy, which would override things defined in Player. You don’t need to name all base classes of Enemy here; just inherit from that one class: … Read more

What does “mro()” do?

Follow along…: >>> class A(object): pass … >>> A.__mro__ (<class ‘__main__.A’>, <type ‘object’>) >>> class B(A): pass … >>> B.__mro__ (<class ‘__main__.B’>, <class ‘__main__.A’>, <type ‘object’>) >>> class C(A): pass … >>> C.__mro__ (<class ‘__main__.C’>, <class ‘__main__.A’>, <type ‘object’>) >>> As long as we have single inheritance, __mro__ is just the tuple of: the class, … Read more