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

This is the code which I plan to use for my game. But it complains for an MRO error. I don't know why. Can someone explains for me? Many thanks.

    class Player:
        pass

    class Enemy(Player):
        pass

    class GameObject(Player, Enemy):
        pass

    g = GameObject()

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:

    class GameObject(Enemy):
        pass

Enemy already includes Player, you don't need to include it again.

From: stackoverflow.com/q/29214888

Back to homepage or read more recommendations: