I have read posts like these:
- What is a metaclass in Python?
- What are your (concrete) use-cases for metaclasses in Python?
- Python's Super is nifty, but you can't use it
but somehow I got confused, many confusions like
when and why i would have to do something like this
#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 it exactly works? (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).
Can someone explain the flow of class instantiation (subclass, metaclass, super, type) and method invocation (
metaclass->__new__, metaclass->__init__, super->__new__, subclass->__init__ inherited from metaclass
) with a well commented working code (though the first link is quite close, but does not talk about cls keyword and super(..) and registry). Preferably an example with multiple inheritance.
P.S.:
made the last part as code because SO formatting was converting the text metaclass->__new__
to metaclass->new
For experts here: please feel free to correct the question if there is a snag.