Detect target name in descriptor __set__ method

Rhodri James rhodri at wildebst.demon.co.uk
Thu Jul 23 16:39:15 CEST 2009


On Thu, 23 Jul 2009 01:05:55 +0100, Gabriel Genellina  
<gagsl-py2 at yahoo.com.ar> wrote:

> En Wed, 22 Jul 2009 11:01:09 -0300, Rhodri James  
> <rhodri at wildebst.demon.co.uk> escribió:
>> On Wed, 22 Jul 2009 06:02:55 +0100, Gabriel Genellina  
>> <gagsl-py2 at yahoo.com.ar> wrote:
>>
>>
>>> class X(object):
>>>    foo = descriptor()
>>>
>>> x = X()
>>> x.foo = "value"
>>
>> Isn't this going to create a brand new instance attribute x.foo that  
>> has nothing to do with the descriptor anyway?
>
> No, it's up to the descriptor __set__ method what happens in this case.  
> Think of the standard 'property' descriptor, the fset function can do  
> whatever it wants.

If it gets called, that is.

> Also, a data descriptor takes precedence over any instance attribute of  
> the same name that might exist.

This was the bit I wasn't clear on.  Thanks!

-- 
Rhodri James *-* Wildebeest Herder to the Masses



More information about the Python-list mailing list