Note: This module is available for backward compatibility only. If you are writing code that does not need to work with versions of Python earlier than Python 2.2, please consider subclassing directly from the built-in dict type.
This module defines a class that acts as a wrapper around dictionary objects. It is a useful base class for your own dictionary-like classes, which can inherit from them and override existing methods or add new ones. In this way one can add new behaviors to dictionaries.
The module also defines a mixin defining all dictionary methods for classes that already have a minimum mapping interface. This greatly simplifies writing classes that need to be substitutable for dictionaries (such as the shelve module).
The UserDict module defines the UserDict class and DictMixin:
In addition to supporting the methods and operations of mappings (see section 2.3.8), UserDict instances provide the following attribute:
This mixin should be used as a superclass. Adding each of the above methods adds progressively more functionality. For instance, defining all but __delitem__ will preclude only pop and popitem from the full interface.
In addition to the four base methods, progessively more efficiency comes with defining __contains__(), __iter__(), and iteritems().
Since the mixin has no knowledge of the subclass constructor, it does not define __init__() or copy().
See About this document... for information on suggesting changes.