Peter Otten <__pete...@web.de> wrote:

> Duncan Booth wrote:
> 
>> The descriptor protocol only works when a value is being accessed or set
>> on an instance and there is no instance attribute of that name so the
>> value is fetched from the underlying class.
> 
> Unlike normal class attributes a descriptor is not shaded by an instance 
> attribute:
> 
>>>> class A(object):
> ...     def set_x(self, value): self.__dict__["x"] = value/2.0
> ...     def get_x(self): return self.__dict__["x"] * 2.0
> ...     x = property(get_x, set_x)
> ...
>>>> a = A()
>>>> a.x = 42
>>>> a.__dict__["x"]
> 21.0
>>>> a.x
> 42.0
>>>> A.x = "something completely different"
>>>> a.x
> 21.0
> 

True, and in fact that's why your suggestion of using two descriptors, one 
at each level works. Thanks for pointing out my mistake.

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to