Inconsistent behavior of descriptors

Michael Chermside mcherm at mcherm.com
Wed Oct 1 15:19:07 EDT 2003


Denis writes:
> I've noticed that the order of attribute lookup is inconsistent
> when descriptor is used.  property instance takes precedence of
> instance attributes:
   [...]
> But it doesn't when I use custom class of descriptor:
   [...]
> Subclasses of property behave like property itself:
   [...]
> Is it an undocumented feature or I have to submit a bug report?

Michael Chermside writes:
> Looks like a bug to me.


John Roth writes:
> I'm not entirely sure what you're describing, however, I
> notice that your descriptor object has a __get__ method,
> but no __set__ or __del__ methods. The lookup chain
> is quite different for descriptors with only __get__ methods
> than it is for descriptors for all three.
> 
> In particular, it's intended that instance attributes should
> be ignored if there is a data descriptor (that is, a descriptor
> with both__get__ and __set__ methods.)

Doh! Of course! John is right of course.

-- Michael Chermside






More information about the Python-list mailing list