making instance data although such alternative forms workmost metaclasses get their work done by redefining the type superclass' __new__ and __init__in practicethis is usually as much control as is requiredand it' often simpler than other schemes moreovermetaclasses have access to additional toolssuch as class methods we'll explore aheadwhich can influence class behavior more directly than some other schemes stillwe'll see later that simple callable-based metaclass can often work much like class decoratorwhich allows the metaclasses to manage instances as well as classes firstthoughthe next section presents an example drawn from the python "twilight zoneto introduce metaclass name resolution concepts overloading class creation calls with metaclasses since they participate in normal oop mechanicsit' also possible for metaclasses to catch the creation call at the end of class statement directlyby redefining the type object' __call__ the redefinitions of both __new__ and __call__ must be careful to call back to their defaults in type if they mean to make class in the endand __call__ must invoke type to kick off the other two hereclasses can catch calls too (but built-ins look in metasnot supers!class supermeta(type)def __call__(metaclassnamesupersclassdict)print('in supermeta call'classnamesupersclassdictsep='\ 'return type __call__(metaclassnamesupersclassdictdef __init__(classclassnamesupersclassdict)print('in supermeta init:'classnamesupersclassdictsep='\ 'print(init class object:'list(class __dict__ keys())print('making metaclass'class submeta(typemetaclass=supermeta)def __new__(metaclassnamesupersclassdict)print('in submeta new'classnamesupersclassdictsep='\ 'return type __new__(metaclassnamesupersclassdictdef __init__(classclassnamesupersclassdict)print('in submeta init:'classnamesupersclassdictsep='\ 'print(init class object:'list(class __dict__ keys())class eggspass print('making class'class spam(eggsmetaclass=submeta)data def meth(selfarg)return self data arg print('making instance' metaclasses invoke submetavia supermeta __call__