Based on my limited Python knowledge Metaclass is another class. In the following example I am just building a metaclass. Here I overloaded the __new__
method. My expectation is at the end of the class declaration when type.__new__()
is called it will be delegated to MyMeta.__new__()
. But that never happens.
print('Building MetaOne')
class MyMeta(type):
def __new__(meta, classname, supers, classdict):
print('In MyMeta:', classname)
def myfunc(self):
print ('In myfunc')
Here from MyMeta
's __new__()
I don't see the print.
But on the contrary if I now use MyMeta
class as a meta class to another class like:
print('Building Another class')
class Super(metaclass = MyMeta):
def myfunc(self):
print ('In Super myfunc')
At the end of this class I see MyMeta's __new__
is getting invoked.
Can some one please help me understand why this happens?