properties + types, implementing meta-class desciptors elegantly?

Michele Simionato mis6 at pitt.edu
Sat Jul 19 10:40:52 EDT 2003


bokr at oz.net (Bengt Richter) wrote in message news:<bfa97g$s5j$0 at 216.39.172.122>...
> 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

I agree with Bengt, from your traceback it seems you are assigning directly
to client.__dict__, but you cannot do that (I think because client.__dict__
is a dictproxy object and not a real dictionary). The right way to
go is via object.__setattr__ , or type.__setattr__ in the case of
metaclasses.

I guess you are aware of the metaclass+properties recipes in the
on-line cookbook, but just in case ...

HTH,


               Michele




More information about the Python-list mailing list