class cc decorator(cas long as we return the original decorated object this way instead of proxywe can manage functions and classes themselvesnot just later calls to them we'll see more realistic examples later in this that use this idea to register callable objects to an api with decoration and assign attributes to functions when they are created coding function decorators on to the code--in the rest of this we are going to study working examples that demonstrate the decorator concepts we just explored this section presents handful of function decorators at workand the next shows class decorators in action following thatwe'll close out with some larger case studies of class and function decorator usage--complete implementations of class privacy and argument range tests tracing calls to get startedlet' revive the call tracer example we met in the following defines and applies function decorator that counts the number of calls made to the decorated function and prints trace message for each callfile decorator py class tracerdef __init__(selffunc)on decorationsave original func self calls self func func def __call__(self*args)on later callsrun original func self calls + print('call % to % (self callsself func __name__)self func(*args@tracer def spam(abc)print( cspam tracer(spamwraps spam in decorator object notice how each function decorated with this class will create new instancewith its own saved function object and calls counter also observe how the *args argument syntax is used to pack and unpack arbitrarily many passed-in arguments this generality enables this decorator to be used to wrap any function with any number of positional argumentsthis version doesn' yet work on keyword arguments or class-level methodsand doesn' return resultsbut we'll fix these shortcomings later in this section nowif we import this module' function and test it interactivelywe get the following sort of behavior--each call generates trace message initiallybecause the decorator class intercepts it this code runs as is under both python and xas does all code coding function decorators