Overriding dict constructor

Christian Heimes lists at cheimes.de
Mon Sep 20 14:00:58 CEST 2010

Am 20.09.2010 13:11, schrieb Steven D'Aprano:
> I have a dict subclass that associates extra data with each value of the 
> key/value items:
> How can I fix this?

Since the dict class is crucial to the overall performance of Python,
the dict class behaves bit different than other classes. I don't know if
this is documented somewhere. Dict methods call the PyDict_GetItem
function directly instead of going through the type's struct.

You have two options to get the desired behavior. Either implement all
functions that call the methods you want to overwrite, or subclass from
something like DictMixin or the appropriate ABC.


More information about the Python-list mailing list