Descriptor puzzlement

John Roth newsgroups at
Thu Jan 8 23:28:02 CET 2004

"Robert Brewer" <fumanchu at> wrote in message
news:mailman.191.1073577858.12720.python-list at
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.

[reply by John Roth]
Interesting thought. What was in the back of my mind for
this experiment was the ability to insert metadata in the
descriptor. I'm still not sure I can do that. I found I couldn't
do it with the property descriptor (at least the experiment I
tried failed, but now that I think of it I might have attempted
it from the instance rather than the class.)

John Roth

Robert Brewer
Amor Ministries
fumanchu at

More information about the Python-list mailing list