Subclassing Python's dict

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Wed Aug 5 16:39:52 CEST 2009


Sergey Simonenko a écrit :
> Hi,
> 
> I subclass builtin 'dict' in my application and experience some problems 
> with it.
> 
> The whole issue is that I should redefine 'setdefault' and 'update' 
> methods after redefining '__setitem__' or/and '__delitem__',
> otherwise 'update' and 'setdefault' ignore redefined '__setitem__' and 
> use builtin dict's one so dict looks kinda like a black box.
> 
> Another guy have reported me that he experiences similar problems with 
> subclassing builtin 'list'.

I indeed notice this behaviour here (Python 2.6.2). I'm afraid it has to 
do with some optimization tricks (dict being the very fundamental data 
structure in Python, it has to be higly optimized).




More information about the Python-list mailing list