[Python-Dev] string-valued fget/fset/fdel for properties

Nicodemus nicodemus at esss.com.br
Mon Nov 24 21:39:39 EST 2003

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
>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 


More information about the Python-Dev mailing list