cannot create my own dict

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Wed Sep 19 15:25:38 EDT 2007


Steve Holden a écrit :
> A.T.Hofkamp wrote:
> 
(snip)

>> So if copying all methods of a native dictionary is not enough, what 
>> should I
>> do to make my class work as a dictionary WITHOUT deriving from dict 
>> (which will
>> obviously work).
>>
> You have to overwrite the "__new__" method to return an object of your 
> new type.

???

This applies to subclasses of immutable types, but I don't see the point 
here. The problem is - as Peter pointed out - that __magic__ methods are 
not looked up in instances when using new-style classes.



More information about the Python-list mailing list