delegation pattern via descriptor

Gregory Ewing greg.ewing at canterbury.ac.nz
Sat Jul 3 22:50:38 EDT 2010


Bruno Desthuilliers wrote:
> kedra marbun a écrit :
> 
>>if we limit our discussion to py:
>>why __{get|set|delete}__ don't receive the 'name' & 'class' from
>>__{getattribute|{set|del}attr}__
>>'name' is the name that is searched
> 
> 
> While it would have been technically possible, I fail to imagine any use
> case for this.

I think he wants to have generic descriptors that are
shared between multiple attributes, but have them do
different things based on the attribute name.

That's not the way property descriptors are designed to
be used -- it's assumed that each attribute will have its
own descriptor, tailored for that particular attribute.

If you want to handle attributes more generically, you
need to intervene at the level of __getattribute__,
__getattr__ and __setattr__.

-- 
Greg



More information about the Python-list mailing list