Re: Descriptors and decorators

2010-10-26 Thread bruno.desthuilli...@gmail.com
On 25 oct, 17:18, Joost Molenaar wrote: > Thanks, Bruno. > Your python-wiki page and walk-through for the Decorator code make it > clear. I now finally understand that methods are in fact ordinary > functions at the time the class is created, and that the descriptor > protocol turns them into boun

Re: Descriptors and decorators

2010-10-25 Thread Joost Molenaar
On 25 October 2010 15:20, bruno.desthuilli...@gmail.com wrote: > So, your decorator is applied to a function, and wraps it into a > Decorator object. Or more exactly, the function is defined, then the > Decorator class is called so a new Decorator object is instanciated > with the function as argu

Re: Descriptors and decorators

2010-10-25 Thread bruno.desthuilli...@gmail.com
On 25 oct, 14:15, Joost Molenaar wrote: > WebOb contains this little nugget of code that allows you to define a > decorator that works on both methods and functions: > > class Decorator(object): >     def __init__(self, func): >         self.func = func >     def __get__(self, object, type=None):

Descriptors and decorators

2010-10-25 Thread Joost Molenaar
WebOb contains this little nugget of code that allows you to define a decorator that works on both methods and functions: class Decorator(object): def __init__(self, func): self.func = func def __get__(self, object, type=None): if type is None: return self