onerous to add the two methods to both classesbut in more complex scenarios this approach can be time-consuming and error-prone if we ever forget to do this consistentlyor we ever need to change the augmentationwe can run into problems metaclass-based augmentation although manual augmentation worksin larger programs it would be better if we could apply such changes to an entire set of classes automatically that waywe' avoid the chance of the augmentation being botched for any given class moreovercoding the augmentation in single location better supports future changes--all classes in the set will pick up changes automatically one way to meet this goal is to use metaclasses if we code the augmentation in metaclassevery class that declares that metaclass will be augmented uniformly and correctly and will automatically pick up any changes made in the future the following code demonstratesextend with metaclass supports future changes better def eggsfunc(obj)return obj value def hamfunc(objvalue)return value 'hamclass extender(type)def __new__(metaclassnamesupersclassdict)classdict['eggs'eggsfunc classdict['ham'hamfunc return type __new__(metaclassnamesupersclassdictclass client (metaclass=extender)def __init__(selfvalue)self value value def spam(self)return self value class client (metaclass=extender)value 'ni? client ('ni!'print( spam()print( eggs()print( ham('bacon') client (print( eggs()print( ham('bacon')this timeboth of the client classes are extended with the new methods because they are instances of metaclass that performs the augmentation when runthis version' exampleadding methods to classes