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

  • Home
  • SEARCH
  • 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 7082639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:04:45+00:00 2026-05-28T07:04:45+00:00

When deriving from a builtin type as well as from some other class, it

  • 0

When deriving from a builtin type as well as from some other class, it seems that the builtin type’s constructor doesn’t call the super class constructor. This results in __init__ methods not being called for types that come after the builtin in the MRO.

Example:

class A:
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        print("A().__init__()")

class B(list, A):
    def __init__(self, *args, **kwargs):
        print("B().__init__() start")
        super().__init__(*args, **kwargs)
        print("B().__init__() end")

if __name__ == '__main__':
    b = B()

In this sample, A.__init__ is never called. When B is defined as class B(A, list) instead — switching the inheritance order — it works as intended (i.e. A.__init__ is called).

This very subtle dependence on inheritance order seems rather un-pythonic, is it intended this way? It also means that you must never derive from builtin types in complex class hierarchies, because you can’t know where the builtin ends up in the MRO when someone else derives from your classes (maintenance horror). Am I missing something?

Extra info: Python version 3.1

  • 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-05-28T07:04:45+00:00Added an answer on May 28, 2026 at 7:04 am

    The correct usage of super() is rather subtle and requires some care if the collaborating methods don’t all have the same signature. The usual pattern for __init__() methods is the following:

    class A(object):
        def __init__(self, param_a, **kwargs):
            self.param_a = param_a
            super(A, self).__init__(**kwargs)
    
    class B(A):
        def __init__(self, param_b, **kwargs):
            self.param_b = param_b
            super(B, self).__init__(**kwargs)
    
    class C(A):
        def __init__(self, param_c, **kwargs):
            self.param_c = param_c
            super(C, self).__init__(**kwargs)
    
    class D(B, C):
        def __init__(self, param_d, **kwargs):
            self.param_d = param_d
            super(D, self).__init__(**kwargs)
    
    d = D(param_a=1, param_b=2, param_c=3, param_d=4)
    

    Note that this requires that all methods collaborate, and that all methods need a somewhat compatible signature to ensure it does not matter at which point the method is called.

    The constructors of built-in types don’t have constructor signatures that allow participating in such a collaboration. Even if they did call super().__init__() this would be rather useless unless all the constructor signatures were unified. So in the end you are right — they are not suitable for particpation in collaborative constructor calls.

    super() can only be used if either all collaborating methods have the same signature (like e.g. __setattr__()) or if you use the above (or a similar) pattern. Using super() isn’t the only pattern to call base class methods, though. If there are no “diamonds” in your multiple inheritance pattern, you can use explicit base class calls, for example B.__init__(self, param_a). Classes with multiple base classes simply call multiple constructors. An even if there are diamonds, you can sometimes use explicit calls, as long as you take care that an __init__() may be called several times without harm.

    If you want to use super() for contructors anyway, you indeed shouldn’t use subclasses of built-in types (except for object) in multiple inheirtance hierachies. Some further reading:

    • Raymond Hettinger’s Python’s super() considered super!
    • James Knight’s Python’s Super is nifty, but you can’t use it
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the following code, I'm implementing an interface, and then deriving from that class
Protected Means, we can access this member only in a deriving class, and internal
I'm building a custom control in Silverlight by deriving from ContentControl and doing some
I have a base class DockedToolWindow : Form, and many classes that derive from
When deriving from a GObject class in PyGTK, you can define GObject properties like
I have a base class Character which has several classes deriving from it. The
I'm having a class where I'm deriving from System.Windows.Forms.Control [Serializable] public class CommonControl :
I know that C# isn't C++ in terms that it restricts you from deriving
I have problem implementing the operator!= in a set class deriving from an abstact
hopefully this is an easy one! I'm deriving from UserControl , and I am

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.