def giveraise(selfpercent)self pay *( percent@tracer def lastname(self)return self name split()[- print('methods 'bob person('bob smith' sue person('sue jones' print(bob namesue namesue giveraise print(int(sue pay)print(bob lastname()sue lastname()giveraise tracer(giveraiseoncall remembers giveraise lastname tracer(lastnameruns oncall(sue runs oncall(bob)lastname in scopes we've also indented the file' self-test code under __name__ test so the decorator can be imported and used elsewhere this version works the same on both functions and methodsbut runs in only due to its nonlocalc:\codepy - calltracer py call to spam call to spam call to eggs methods bob smith sue jones call to giveraise call to lastname call to lastname smith jones trace through these results to make sure you have handle on this modelthe next section provides an alternative to it that supports classesbut is also substantially more complex using descriptors to decorate methods although the nested function solution illustrated in the prior section is the most straightforward way to support decorators that apply to both functions and class-level methodsother schemes are possible the descriptor feature we explored in the prior for examplecan help here as well recall from our discussion in that that descriptor is normally class attribute assigned to an object with __get__ method run automatically whenever that attribute is referenced and fetchednew-style class object derivation is required for descriptors in python xbut not xclass descriptor(object)def __get__(selfinstanceowner) decorators