The test code is as follows:
1 classModelmetaclass (type):2 def __new__(cls,name,base,attrs):3Logging.info ("CLS is:"+str (CLS))4Logging.info ("name is:"+STR (name))5Logging.info ("Base is:"+Str (base))6Logging.info ("Attrs is:"+str (attrs))7 returnType.__new__(cls,name,base,attrs)8 Pass9 PassTen One classModel (dict): A __metaclass__=Modelmetaclass - def __init__(self): - Pass the Pass - - defMain (): -m=Model () + - if __name__=='__main__': +Main ()
Test results:
1INFO:root:cls is:<class '__main__. Modelmetaclass'>2INFO:root:name is: Model3INFO:root:base is:(<type'Dict'>,)4INFO:root:attrs is:{'__module__':'__main__','__metaclass__': <class '__main__. Modelmetaclass','__init__': <function__init__At 0x025c76f0>}
The conclusion is obvious. The CLS is the name of the current class, that is, the class itself. Name is a class that points to modelmetaclass through the __metaclass__ property, which is the class to instantiate, and Modelmetaclass intercepts the instantiation of the class. Base is the base class for the class to instantiate. Attrs is a collection of properties for the class to instantiate.
Description of the type constructor parameter in Python