The module defines a mixin, DictMixin, 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).
This module also defines a class, UserDict, that acts as a wrapper around dictionary objects. The need for this class has been largely supplanted by the ability to subclass directly from dict (a feature that became available starting with Python version 2.2). Prior to the introduction of dict, the UserDict class was used to create dictionary-like sub-classes that obtained new behaviors by overriding existing methods or adding new ones.
The UserDict module defines the UserDict class and DictMixin:
for key in myDict).
In addition to supporting the methods and operations of mappings (see section 3.8), UserDict and IterableUserDict 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, progressively 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.