class @decorator def method(selfxy) instance not in argsmethod decorator(methodrebound to decorator instance when coded this waythe decorated method is rebound to an instance of the decorator classinstead of simple function the problem with this is that the self in the decorator' __call__ receives the decora tor class instance when the method is later runand the instance of class is never included in *args this makes it impossible to dispatch the call to the original method --the decorator object retains the original method functionbut it has no instance to pass to it to support both functions and methodsthe nested function alternative works betterdef decorator( )def wrapper(*args) is func or method without instance class instance in args[ for method (*argsruns func or method return wrapper @decorator def func(xy)func( func decorator(funcreally calls wrapper( class @decorator def method(selfxy)method decorator(methodrebound to simple function ( method( really calls wrapper( when coded this way wrapper receives the class instance in its first argumentso it can dispatch to the original method and access state information technicallythis nested-function version works because python creates bound method object and thus passes the subject class instance to the self argument only when method attribute references simple functionwhen it references an instance of callable class insteadthe callable class' instance is passed to self to give the callable class access to its own state information we'll see how this subtle difference can matter in more realistic examples later in this also note that nested functions are perhaps the most straightforward way to support decoration of both functions and methodsbut not necessarily the only way the prior descriptorsfor examplereceive both the descriptor and subject class instance when called though more complexlater in this we'll see how this tool can be leveraged in this context as well decorators