we could not use plain decorator because we want to pass arguments to the decoratorso we have instead created function that takes our arguments and that returns class decorator the decorator itself takes single argumenta class (just as function decorator takes single function or method as its argumentwe must use nonlocal so that the nested function uses the attribute_name from the outer scope rather than attempting to use one from its own scope and we must be able to correct the attribute name if necessary to take account of the name mangling of private attributes the decorator' behavior is quite simpleit iterates over all the method names that the delegate(function has been givenand for each one creates new method which it sets as an attribute on the class with the given method name we have used eval(to create each of the delegated methods since it can be used to execute single statementand lambda statement produces method or function for examplethe code executed to produce the pop(method islambda self* **kwself _sortedlist__list pop(* **kwwe use the and *argument forms to allow for any arguments even though the methods being delegated to have specific argument lists for examplelist pop(accepts single index position (or nothingin which case it defaults to the last itemthis is okay because if the wrong number or kinds of arguments are passedthe list method that is called to do the work will raise an appropriate exception fuzzybool the second class decorator we will review was also used in when we implemented the fuzzybool class we mentioned that we had supplied only the __lt__(and __eq__(special methods (for and ==)and had generated all the other comparison methods automatically what we didn' show was the complete start of the class definition@util complete_comparisons class fuzzyboolthe other four comparison operators were provided by the complete_comparisons(class decorator given class that defines only (or and ==)the decorator produces the missing comparison operators by using the following logical equivalencesx ( xx ( yx> < < ( xx > ( yif the class to be decorated has and ==the decorator will use them bothfalling back to doing everything in terms of if that is the only operator