Python descriptors are not transparent when they're first used

Seth Gordon sethg-Dp9fwfP21SfQT0dZR+AlfA at public.gmane.org
Tue Jul 31 13:23:33 EDT 2007


Cole Tuininga wrote:
> What you've done is to set the attributes Foo.bar, Foo.baz, and Foo.quux
> to instances of the WriteOnly class.  However, because Foo.bar is a
> reference (just like everything in Python), doing this:
> 
> foo.bar = 4
> 
> overrides the 'bar' attribute of the instance known as foo.  It is no
> longer a 'WriteOnly' instance.  If you did a print str(type(foo.bar)),
> it would report that it is now an instance of an Integer object.

Crap.  I thought "foo.bar = 4" would automagically be translated to
"foo.bar.__set__(foo.bar, 4)".

I have *completely* misunderstood the documentation for descriptors.
What's the point of all that __get__, __set__, and __delete__ magic?


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.






More information about the Discuss mailing list