Guido van Rossum wrote: >You could then >also do away with the metaclass, but you'd be back at Nicodemus's >proposal, and that seems to incur too much overhead (we could use >heavy caching, but it would be a bit hairy). > > I think the overhead is very small, unless I'm overlooking something. The only extra overhead that I see is the extra lookup every time the property is accessed, which is the same as calling a method. But I agree that this difference could be significant for some applications. >Anyway, all of this can be implemented easily by subclassign property >or by defining your own descriptor class -- there's no magic, just >define __get__ and __set__ (and __delete__ and __doc__, to be >complete). > >So maybe somebody should implement this for themselves and find out >how often they really use it. > > Actually, I already did it. 8) The class accepts functions just like property does, but keeps only the names of the functions, and uses getattr in __get__ and __set__ to access the actual functions (nothing magical, as you pointed it out). I use it quite often, and the biggest advantage is that when you *do* need to overwrite one of the property's methods, you don't have to change anything in the base class: you just overwrite the method in the derived class and that's it. So as a rule, I always use this property instead of the built-in, but that's for other reasons besides easy subclassing. Regards, Nicodemus.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4