[Python-Dev] RFC: readproperty

Phillip J. Eby pje at telecommunity.com
Wed Sep 28 21:00:55 CEST 2005


At 05:28 PM 9/28/2005 +0000, Žiga Seilnacht wrote:

>You can use something like this to find a descriptor's name:
 > <snip>

The given code fails if the same property appears under more than one name 
or is used in more than one class.  It also requires the property object to 
be mutable, and is subject to inter-thread race conditions in the case of 
modification of a class.  It also doesn't work for class-level descriptors 
(added to the class' class), and I'd prefer it to use the logical 
equivalent of ob.__dict__.setdefault() rather than setattr(ob,...) so that 
it's free of (simple) race conditions in the case where one thread sets the 
attribute while another is computing the default value.

While these aren't crippling limitations in a given application, I think 
the stdlib implementation should be a bit more robust, especially since 
none of these features is very hard to implement, once you know what's 
needed.  (And I already have a robust implementation that could be cribbed 
from.)

In any case, having a stdlib version that doesn't address those issues 
wouldn't be very useful for me, as it wouldn't allow me to replace my 
custom C descriptor and metaclass.  If we added __bind__ (or something like 
it) to the descriptor protocol I could get rid of *at least* that 
metaclass, and maybe others.



More information about the Python-Dev mailing list