__call__ would be passed tracer instance onlyas we'll see in part viiithere are variety of ways to code function decoratorsincluding nested def statementssome of the alternatives are better suited to methods than the version shown here for exampleby using nested functions with enclosing scopes for stateinstead of callable class instances with attributesfunction decorators often become more broadly applicable to class-level methods too we'll postpone the full details on thisbut here' brief look at this closure based coding modelit uses function attributes for counter state for portabilitybut could leverage variables and nonlocal instead in onlydef tracer(func)remember original def oncall(*args)on later calls oncall calls + print('call % to % (oncall callsfunc __name__)return func(*argsoncall calls return oncall class @tracer def spam(self,abc)return (print( spam( )print( spam(' '' '' ')same output as tracer (in tracer pya first look at class decorators and metaclasses function decorators turned out to be so useful that python and expanded the modelallowing decorators to be applied to classes as well as functions in shortclass decorators are similar to function decoratorsbut they are run at the end of class statement to rebind class name to callable as suchthey can be used to either manage classes just after they are createdor insert layer of wrapper logic to manage instances when they are later created symbolicallythe code structuredef decorator(aclass)@decorator class cclass decoration syntax is mapped to the following equivalentdef decorator(aclass)class cc decorator(cname rebinding equivalent the class decorator is free to augment the class itselfor return proxy object that intercepts later instance construction calls for examplein the code of the section "counting instances per class with class methodson page we could use this advanced class topics