On 7/24/07, <b class="gmail_sendername">Ron Adam</b> <<a href="mailto:rrr@ronadam.com">rrr@ronadam.com</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>>> The same object in a class might look like...<br>>><br>>> property foo(self):<br>>>     self.__value__ = None<br>>>     def __get__(self):<br>>>         return self.__value__<br>
>>     def __set__(self, value):<br>>>         self.__value__ = value<br>><br>> In the first version, how is anything supposed to know that<br>> the __value__ inside the function is an implicit attribute
<br>> of self rather than a local variable of the function<br><br>In the first example self isn't implicit, it's non-existent.  It would work<br>more like a generator that yields it value on gets, and receives its value
<br>on sets.<br><br>In the second version self is passed to the functions explicitly so it can<br>work in an instance.  But other than that it's the same.  It could also<br>keep state between calls, in which case all instances of that class would
<br>share those values.  (just like instances share class attributes)<br><br>   class bar(object):<br>      property foo(self):<br>          countgets = 0<br>          self.__value__ = None<br>          def __get__()<br>              countgets += 1
<br>              return countgets, self.__value__<br>          def __set__(value)<br>              self.__value__ = value<br><br>In this case countgets will be the total gets of all subclasses of bar.<br><br>This could be done with a class attribute as well, but that breaks the idea
<br>of having a single self contained component.  Having self contained<br>components is more conducive to a modular design where you can more easily<br>reuse parts.</blockquote><div><br>Pardon me for interrupting... Don't the existing descriptors do all of this, with almost exactly the same syntax? You just have to set a class variable to an instance of the descriptor class, which is one extra line of code. Additionally, this allows reuse of a descriptor class for multiple properties, which as-far-as-I-can-tell your models don't.
<br><br>Perhaps I'm missing something, but I can't see the actual benefit of your suggestions (besides inline-ing of properties' names).<br><br>- Tal</div></div>