properties + types, implementing meta-class desciptors elegantly?

Bengt Richter bokr at oz.net
Fri Jul 18 22:08:48 EDT 2003


On Fri, 18 Jul 2003 08:48:44 -0400, "Mike C. Fletcher" <mcfletch at rogers.com> wrote:

>Hi all,
>
>I'm working on a base meta-type for a plug-in system, and I'd really 
>like to use the same rich-descriptor objects as I've used everywhere 
>else in the system.  Basically these are descriptors that intercept 
>x.name, do various transformations, and then store the values in the 
>instance dictionary.
>
>Unfortunately:
>
> >>> type(t).pluginRole
>Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
>  File "p:\properties\basicproperty\basic.py", line 231, in __get__
>    return self.getDefault( client )
>  File "p:\properties\basicproperty\basic.py", line 256, in getDefault
>    setattr( client, self.name, value )
>  File "p:\properties\basicproperty\basic.py", line 283, in __set__
>    self._setValue( client, value )
>  File "p:\properties\basicproperty\basic.py", line 151, in _setValue
>    client.__dict__[ self.name ] = value
>TypeError: object does not support item assignment
>
Not sure exactly what you are doing, but what does

     object.__setattr__(client, self.name, value)

do in your context in place of

     client.__dict__[ self.name ] = value

?

Regards,
Bengt Richter




More information about the Python-list mailing list