although they have special rolemetaclasses are coded with class statements and follow the usual oop model in python for exampleas subclasses of typethey can redefine the type object' methodsoverriding and customizing them as needed metaclasses typically redefine the type class' __new__ and __init__ to customize class creation and initialization although it' less commonthey can also redefine __call__ if they wish to catch the end-of-class creation call directly (albeit with the complexities we saw in the prior section)and can even be simple functions or other callables that return arbitrary objectsinstead of type subclasses metaclass declarations are inherited by subclasses the metaclass= declaration in user-defined class is inherited by the class' normal subclassestooso the metaclass will run for the construction of each class that inherits this specification in superclass inheritance chain metaclass attributes are not inherited by class instances metaclass declarations specify an instance relationshipwhich is not the same as what we've called inheritance thus far because classes are instances of metaclassesthe behavior defined in metaclass applies to the classbut not the class' later instances instances obtain behavior from their classes and superclassesbut not from any metaclasses technicallyattribute inheritance for normal instances usually searches only the __dict__ dictionaries of the instanceits classand all its superclassesmetaclasses are not included in inheritance lookup for normal instances metaclass attributes are acquired by classes by contrastclasses do acquire methods of their metaclasses by virtue of the instance relationship this is source of class behavior that processes classes themselves technicallyclasses acquire metaclass attributes through the class' __class__ link just as normal instances acquire names from their classbut inheritance via __dict__ search is attempted firstwhen the same name is available to class in both metaclass and superclassthe superclass (inheritanceversion is used instead of that on metaclass (instancethe class' __class__howeveris not followed for its own instancesmetaclass attributes are made available to their instance classesbut not to instances of those instance classes (and see the earlier reference to dr seuss this may be easier to understand in code than in prose to illustrate all these pointsconsider the following examplefile metainstance py class metaone(type)def __new__(metaclassnamesupersclassdict)redefine type method print('in metaone new:'classnamereturn type __new__(metaclassnamesupersclassdictdef toast(self)return 'toastinheritance and instance