Descriptor puzzlement

Robert Brewer fumanchu at amor.org
Thu Jan 8 10:58:16 EST 2004


Peter Otten wrote:
> John Roth wrote:
> > It doesn't look like the descriptor protocol is getting
> > invoked at all.
> 
> The descriptor protocol works on the class, not the instance, so 
> 
> class AnotherObject(object):
>     prop = AnObject("snafu")
> 
> or something similar should work. This means in particular 
> that you have to
> store the property's state in the AnotherObject rather than 
> the AnObject
> instance.

I got bit by this myself, a while ago. Would there be any benefit to
providing something like what John wanted, where the descriptor can
maintain its own state, and be referenced by the owner instance (instead
of the owner class)? I could sure use it in a couple of spots where my
__getattr__/__setattr__ code is getting ugly.


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org




More information about the Python-list mailing list