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 101471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:46:39+00:00 2026-05-11T00:46:39+00:00

I have read posts like these: What is a metaclass in Python? What are

  • 0

I have read posts like these:

  1. What is a metaclass in Python?
  2. What are your (concrete) use-cases for metaclasses in Python?
  3. Python’s Super is nifty, but you can’t use it

But somehow I got confused. Many confusions like:

When and why would I have to do something like the following?

# Refer link1 return super(MyType, cls).__new__(cls, name, bases, newattrs) 

or

# Refer link2 return super(MetaSingleton, cls).__call__(*args, **kw) 

or

# Refer link2 return type(self.__name__ + other.__name__, (self, other), {}) 

How does super work exactly?

What is class registry and unregistry in link1 and how exactly does it work? (I thought it has something to do with singleton. I may be wrong, being from C background. My coding style is still a mix of functional and OO).

What is the flow of class instantiation (subclass, metaclass, super, type) and method invocation (

metaclass->__new__, metaclass->__init__, super->__new__, subclass->__init__ inherited from metaclass 

) with well-commented working code (though the first link is quite close, but it does not talk about cls keyword and super(..) and registry). Preferably an example with multiple inheritance.

P.S.: I made the last part as code because Stack Overflow formatting was converting the text metaclass->__new__ to metaclass->new

  • 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. 2026-05-11T00:46:39+00:00Added an answer on May 11, 2026 at 12:46 am

    OK, you’ve thrown quite a few concepts into the mix here! I’m going to pull out a few of the specific questions you have.

    In general, understanding super, the MRO and metclasses is made much more complicated because there have been lots of changes in this tricky area over the last few versions of Python.

    Python’s own documentation is a very good reference, and completely up to date. There is an IBM developerWorks article which is fine as an introduction and takes a more tutorial-based approach, but note that it’s five years old, and spends a lot of time talking about the older-style approaches to meta-classes.

    super is how you access an object’s super-classes. It’s more complex than (for example) Java’s super keyword, mainly because of multiple inheritance in Python. As Super Considered Harmful explains, using super() can result in you implicitly using a chain of super-classes, the order of which is defined by the Method Resolution Order (MRO).

    You can see the MRO for a class easily by invoking mro() on the class (not on an instance). Note that meta-classes are not in an object’s super-class hierarchy.

    Thomas‘ description of meta-classes here is excellent:

    A metaclass is the class of a class. Like a class defines how an instance of the class behaves, a metaclass defines how a class behaves. A class is an instance of a metaclass.

    In the examples you give, here’s what’s going on:

    1. The call to __new__ is being bubbled up to the next thing in the MRO. In this case, super(MyType, cls) would resolve to type; calling type.__new__ lets Python complete it’s normal instance creation steps.

    2. This example is using meta-classes to enforce a singleton. He’s overriding __call__ in the metaclass so that whenever a class instance is created, he intercepts that, and can bypass instance creation if there already is one (stored in cls.instance). Note that overriding __new__ in the metaclass won’t be good enough, because that’s only called when creating the class. Overriding __new__ on the class would work, however.

    3. This shows a way to dynamically create a class. Here’s he’s appending the supplied class’s name to the created class name, and adding it to the class hierarchy too.

    I’m not exactly sure what sort of code example you’re looking for, but here’s a brief one showing meta-classes, inheritance and method resolution:

    print('>>> # Defining classes:')  class MyMeta(type):     def __new__(cls, name, bases, dct):         print("meta: creating %s %s" % (name, bases))         return type.__new__(cls, name, bases, dct)      def meta_meth(cls):         print("MyMeta.meta_meth")      __repr__ = lambda c: c.__name__  class A(metaclass=MyMeta):     def __init__(self):         super(A, self).__init__()         print("A init")      def meth(self):         print("A.meth")  class B(metaclass=MyMeta):     def __init__(self):         super(B, self).__init__()         print("B init")      def meth(self):         print("B.meth")  class C(A, B, metaclass=MyMeta):     def __init__(self):         super(C, self).__init__()         print("C init")  print('>>> c_obj = C()') c_obj = C() print('>>> c_obj.meth()') c_obj.meth() print('>>> C.meta_meth()') C.meta_meth() print('>>> c_obj.meta_meth()') c_obj.meta_meth() 

    Example output (using Python >= 3.6):

    >>> # Defining classes: meta: creating A () meta: creating B () meta: creating C (A, B) >>> c_obj = C() B init A init C init >>> c_obj.meth() A.meth >>> C.meta_meth() MyMeta.meta_meth >>> c_obj.meta_meth() Traceback (most recent call last): File "metatest.py", line 41, in <module>     c_obj.meta_meth() AttributeError: 'C' object has no attribute 'meta_meth' 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 61k
  • Answers 61k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Should be in Users\\Documents It might be in a subdirectory… May 11, 2026 at 9:38 am
  • added an answer One of your comments betrays that you are not using… May 11, 2026 at 9:38 am
  • added an answer That's the focusing border added by the browser. For usability… May 11, 2026 at 9:38 am

Related Questions

I have read posts like these: What is a metaclass in Python? What are
I have read in some of the ClickOnce posts that ClickOnce does not allow
Alright...I've given the site a fair search and have read over many posts about
I've read a few posts where people have stated (not suggested, not discussed, not
I have read this post about how to test private methods. I usually do
I have read the post here about using setTimeout() during intensive DOM processing (using
I have read the very good blog post of Rob Conery Crazy Talk: Reducing
I have read through several reviews on Amazon and some books seem outdated. I
I have read a lot that LISP can redefine syntax on the fly, presumably
I have read about partial methods in the latest C# language specification , so

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.