the prior metaclass example works for just one specific function decorator--tracing howeverit' trivial to generalize this to apply any decorator to all the methods of class all we have to do is add an outer scope layer to retain the desired decoratormuch like we did for decorators in the prior the followingfor examplecodes such generalization and then uses it to apply the tracer decorator againmetaclass factoryapply any decorator to all methods of class from types import functiontype from decotools import tracertimer def decorateall(decorator)class metadecorate(type)def __new__(metaclassnamesupersclassdict)for attrattrval in classdict items()if type(attrvalis functiontypeclassdict[attrdecorator(attrvalreturn type __new__(metaclassnamesupersclassdictreturn metadecorate class person(metaclass=decorateall(tracer))def __init__(selfnamepay)self name name self pay pay def giveraise(selfpercent)self pay *( percentdef lastname(self)return self name split()[- apply decorator to all bob person('bob smith' sue person('sue jones' print(bob namesue namesue giveraise print(' fsue payprint(bob lastname()sue lastname()when this code is run as it isthe output is again the same as that of the previous examples--we're still ultimately decorating every method in client class with the tracer function decoratorbut we're doing so in more generic fashionc:\codepy - decoall-meta-any py call to __init__ call to __init__ bob smith sue jones call to giveraise call to lastname call to lastname smith jones nowto apply different decorator to the methodswe can simply replace the decorator name in the class header line to use the timer function decorator shown earlierfor exampleapplying decorators to methods