summaryrefslogtreecommitdiffstats
path: root/Doc/lib/libuserdict.tex
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2002-11-15 06:46:14 (GMT)
committerRaymond Hettinger <python@rcn.com>2002-11-15 06:46:14 (GMT)
commit7994716b6bcaeca64f47b7b3ed4e411bb6afc415 (patch)
tree0815d4b85257de2a72984d5c7026dab279b053e7 /Doc/lib/libuserdict.tex
parent3a7f405f5b3388b5ba3cf807100627ae5fbf696f (diff)
downloadcpython-7994716b6bcaeca64f47b7b3ed4e411bb6afc415.zip
cpython-7994716b6bcaeca64f47b7b3ed4e411bb6afc415.tar.gz
cpython-7994716b6bcaeca64f47b7b3ed4e411bb6afc415.tar.bz2
SF patch #520382: Expand shelve.py to have a full dictionary interface
and add a mixin to UserDict.py to make it easier to implement a full dictionary interface.
Diffstat (limited to 'Doc/lib/libuserdict.tex')
-rw-r--r--Doc/lib/libuserdict.tex25
1 files changed, 24 insertions, 1 deletions
diff --git a/Doc/lib/libuserdict.tex b/Doc/lib/libuserdict.tex
index d665686..e01c546 100644
--- a/Doc/lib/libuserdict.tex
+++ b/Doc/lib/libuserdict.tex
@@ -15,7 +15,13 @@ 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{UserDict} module defines the \class{UserDict} class:
+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 \module{UserDict} module defines the \class{UserDict} class
+and \class{DictMixin}:
\begin{classdesc}{UserDict}{\optional{initialdata}}
Class that simulates a dictionary. The instance's
@@ -35,6 +41,23 @@ A real dictionary used to store the contents of the \class{UserDict}
class.
\end{memberdesc}
+\begin{classdesc}{DictMixin}{}
+Mixin defining all dictionary methods for classes that already have
+a minimum dictionary interface including\method{__getitem__},
+\method{__setitem__}, \method{__delitem__}, and \method{keys}.
+
+This mixin should be used as a superclass. Adding each of the
+above methods adds progressively more functionality. For instance,
+the absence of \method{__delitem__} precludes only \method{pop}
+and \method{popitem}.
+
+While the four methods listed above are sufficient to support the
+entire dictionary interface, progessively more efficiency comes
+with defining \method{__contains__}, \method{__iter__}, and
+\method{iteritems}.
+
+\end{classdesc}
+
\section{\module{UserList} ---
Class wrapper for list objects}