Mike C. Fletcher a écrit : > bruno modulix wrote: > >> Mike C. Fletcher wrote: >> (snip) >> >> >>> Though the don't go into extreme detail on decorators (they are >>> basically syntactic sugar for a particular type of descriptor). >>> >>> >> >> Err... Could you elaborate on this ? Decorators are syntactic sugar for >> function wrapping, while descriptors are a 'protocol' to hook into >> attribute lookup, so I don't really see how one can describe the first >> in terms of the second... >> >> > There are two major types of descriptors, the elven and the dwarven. > > * Elven descriptors are things like property, BasicProperty, VRML97 > fields, Zope Field Properties, or PEAK's mechanisms. They mediate > access to an instance's attributes, (both setting and getting of > values) and are used primarily for domain modeling. > * Dwarven descriptors are things like staticmethod or classmethod; > function-like things that tend to look like a function and quack > like a function, but have some special property or functionality > attached when accessed as an attribute of a class/instance > (functions themselves return instance methods or class methods > depending on how they are retrieved). >
Ok, I see... In fact, while reading your explanations, it reminded me of some experiments I made recently playing with descriptors, decorators and metaclasses to use callable objects implementing the descriptor protocol as instance methods of other objects (I don't know if I'll ever find a use case for this trick, but what, they're a lot of things in Python I never thought I could find a use case for at first and that I'd have hard time living without nowadays...). > > HTH, It did, thanks. -- http://mail.python.org/mailman/listinfo/python-list