type __init__(classclassnamesuperclassesattributedictthe __new__ method creates and returns the new class objectand then the __init__ method initializes the newly created object as we'll see in momentthese are the hooks that metaclass subclasses of type generally use to customize classes for examplegiven class definition like the following for spamclass eggsinherited names here class spam(eggs)data def meth(selfarg)return self data arg inherits from eggs class data attribute class method attribute python will internally run the nested code block to create two attributes of the class (data and meth)and then call the type object to generate the class object at the end of the class statementspam type('spam'(eggs,){'data' 'meth'meth'__module__''__main__'}in factyou can call type this way yourself to create class dynamically--albeit here with fabricated method function and empty superclasses tuple (python adds object automatically in both and ) type('spam'(){'data' 'meth'(lambda xyx data )} (xi ( datai meth( ( the class produced is exactly like that you' get from running class statementx __bases__ (,[(avfor (avin __dict__ items(if not startswith('__')[('data' )('meth'at >)because this type call is made automatically at the end of the class statementthoughit' an ideal hook for augmenting or otherwise processing class the trick lies in replacing the default type with custom subclass that will intercept this call the next section shows how declaring metaclasses as we've just seenclasses are created by the type class by default to tell python to create class with custom metaclass insteadyou simply need to declare metaclass to intercept the normal instance creation call in user-defined class how you do so depends on which python version you are using metaclasses