We now understand how Python uses descriptors in functions to make them work as methods when they are defined inside a class. We have also seen examples of cases where we can make decorators work by making them comply with the descriptor protocol by using the __get__() method of the interface to adapt the decorator to the object it is being called with. This solves the problem for our decorators in the same way that Python solves the issue of functions as methods in objects.
The general recipe for adapting a decorator in such a way is to implement the __get__() method on it and use types.MethodType to convert the callable (the decorator itself) to a method bound to the object it is receiving (the ...