Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8190357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:36:08+00:00 2026-06-07T03:36:08+00:00

I was playing around with the multiple inheritance in python and I come a

  • 0

I was playing around with the multiple inheritance in python and I come a cross a situation that I can’t understand how it happen.

Here is the inheritance layout:

    A       F
  /   \     |
 B     C    |   
  \    |   /
    \  |  /   
       D

The ABCD diamond that everyone familiar with.
Plus an extra class "F" I throw it in for fun.

Here is the code:

class A(object):
    def foo(self, call_from):
        print "foo from A, call from %s" % call_from
        super(A, self).foo("A")

class B(A):
    def foo(self, call_from):
        print "foo from B, call from %s" % call_from
        super(B, self).foo("B")

class C(A):
    def foo(self, call_from):
        print "foo from C, call from %s" % call_from
        super(C, self).foo("C")

class F(object):
    def foo(self, call_from):
        print "foo from F, call from %s" % call_from

class D(B, C, F):
    def foo(self):
        print "foo from D"
        super(D, self).foo("D")

output:

>>> d = D()
>>> d.foo()
foo from D
foo from B, call from D
foo from C, call from B
foo from A, call from C
foo from F, call from A

The method resolution order:

>>> D.__mro__
(<class '__main__.D'>, <class '__main__.B'>, <class '__main__.C'>, <class '__main__.A'>, <class '__main__.F'>, <type 'object'>)
  • foo from C, call from B instead of foo from C, call from D
  • foo from F, call from A just simply throw me off…

It seems like the super() are chained up according to the method resolution order and ignore the relationship between classes, but I not sure.

Can someone point me to the right direction to understand this behavior?

Please keep in mind that I’m trying to understand the language itself. Not trying to solve a practical problem. So I don’t have an use case for this. But it will be nice if someone can point out an use case 🙂


UPDATE:

To summarize – super() simply let you know what is next to call base on the mro. It is not necessary the parent. While mro built base on the inheritance hierarchy, mro itself is not the inheritance hierarchy.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:36:11+00:00Added an answer on June 7, 2026 at 3:36 am

    The whole point of super() is to follow the method resolution order. That’s why you tell it your own class, not your parent class. It’s hard for the programmer to predict which class will be invoked next, so you let super() take care of it.

    You already had B called from D, so how could you then get C called from D? D.foo() can only call one other foo(), because you only have one function call there. It’s going to be a linear chain of calls, so the classes have to be linearized, that’s what the method resolution order does.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been playing around with Simple.Data and have run across something that I can't
So I'm playing around with regular expressions in Python. Here's what I've gotten so
Playing around with Python - tkInter - Entry widget - when I use validatecommand
Playing around with MongoDB and NoRM in .NET. Thing that confused me - there
Been playing around with this for a couple of hours and can't seem to
Just playing around with memcache for the first time; here's my code: $memcache =
While playing around with some hooks I noticed that the output from the hooks
I have long programming background, but am new to Python, and am playing around
I'm playing around with OData with PowerPivot and I would like to know can
I was playing around with the LG LG P990 optimus speed and noticed that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.