class TestMetaClass(type):
def __new__(mcs, *args, **kwargs):
print('TestMetaClass.__new__', mcs)
return type.__new__(mcs, *args, **kwargs)
def __init__(cls, name, bases, kwds):
print('TestMetaClass.__init__', cls)
super(TestMetaClass, cls).__init__(name, bases, kwds)
def __call__(cls, *args, **kwargs):
print('TestMetaClass.__call__')
return super(TestMetaClass, cls).__call__(*args, **kwargs)
class A(metaclass=TestMetaClass):
def __new__(cls, *args, **kwargs):
print('A.__new__')
return super(A, cls).__new__(cls)
def __init__(self, name=None):
self.name = name
print('A.__init__')
A('hello')
展开