[Python] Why is this an ambiguous MRO?

Discussão em 'Python' iniciado por Stack, Setembro 7, 2025.

  1. Stack

    Stack Membro Participativo

    class First(object):
    def __init__(self):
    print("first")

    class Second(First):
    def __init__(self):
    print("second")

    class Third(First, Second):
    def __init__(self):
    print("third")


    Source

    Why can't Python create a consistent MRO? It seems to me it's pretty clear:

    1. Search in First if method does not exist in Third
    2. Search in Second if method does not exist in First

    But if you try it out:

    TypeError: Error when calling the metaclass bases
    Cannot create a consistent method resolution
    order (MRO) for bases First, Second

    Continue reading...

Compartilhe esta Página