DEV Community

Taleb
Taleb

Posted on

3

MRO


class Base:
    def __init__(self):
        print('Base.__init__')

class Child1(Base):
    def __init__(self):
        Base.__init__(self)
        print('Child1.__init__')

class Child2(Base):
    def __init__(self):
        Base.__init__(self)
        print('Child2.__init__')

class Child3(Base):
    def __init__(self):
        Child1.__init__(self)
        Child2.__init__(self)
        print('Child3.__init__')


c3 = Child3()


check print output is this what you expected !
Base.__init__
Child1.__init__
Base.__init__
Child2.__init__
Child3.__init__

and now try this

class Base:
    def __init__(self):
        print('Base.__init__')

class Child1(Base):
    def __init__(self):
        super().__init__()
        print('Child1.__init__')

class Child2(Base):
    def __init__(self):
        super().__init__()
        print('Child2.__init__')

class Child3(Child1, Child2):
    def __init__(self):
        super().__init__()
        print('Child3.__init__')


c3 = Child3()
print(Child3.__mro__)

(<class '__main__.Child3'>, <class '__main__.Child1'>, <class '__main__.Child2'>, <class '__main__.Base'>, <class 'object'>)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

While many AI coding tools operate as simple command-response systems, Qodo Gen 1.0 represents the next generation: autonomous, multi-step problem-solving agents that work alongside you.

Read full post →

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay