I am playing with metaclasses in Python 2.7. So I created a code that looks like this:
class M(type):
def __new__(meta, name, parents, attrs):
print 'In meta new'
return super(meta, meta).__new__(meta, name, parents, attrs)
def __init__(cls, *args, **kwargs):
print 'In meta init'
def __call__(cls, *attr, **val):
print 'In meta call'
return super(cls, cls).__new__(cls)
class A(object):
__metaclass__ = M
def __new__(cls):
print 'In class new'
return super(cls, cls).__new__(cls)
def __init__(self):
print 'In object init'
def __call__(self):
print 'In object call'
But the output confuses me:
A()
In meta new
In meta init
In meta call
Somehow class methods __ new __ and __ init __ were overridden, so interpreter just skip them. Can anyone explain this stuff?
Thanks for your help.