diff options
author | Raymond Hettinger <python@rcn.com> | 2002-11-18 04:34:10 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2002-11-18 04:34:10 (GMT) |
commit | 8ddc176e2e7ef11b2c46062b29563bc776f177b8 (patch) | |
tree | 9420f4a710a3ae47f72c846c0b6f5e0c1a9a29bd /Doc/lib | |
parent | 782d9408667f8df924d865088839633f53cf89bc (diff) | |
download | cpython-8ddc176e2e7ef11b2c46062b29563bc776f177b8.zip cpython-8ddc176e2e7ef11b2c46062b29563bc776f177b8.tar.gz cpython-8ddc176e2e7ef11b2c46062b29563bc776f177b8.tar.bz2 |
Improve DictMixin.
Replaced docstring with comments. Prevents subclass contamination.
Added the missing __cmp__() method and a test for __cmp__().
Used try/except style in preference to has_key() followed by a look-up.
Used iteritem() where possible to save creating a long key list and
to save redundant lookups.
Expanded .update() to look for the most helpful methods first and gradually
work down to a mininum expected interface.
Expanded documentation to be more clear on how to use the class.
Diffstat (limited to 'Doc/lib')
-rw-r--r-- | Doc/lib/libuserdict.tex | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/Doc/lib/libuserdict.tex b/Doc/lib/libuserdict.tex index e01c546..ef5c1bf 100644 --- a/Doc/lib/libuserdict.tex +++ b/Doc/lib/libuserdict.tex @@ -43,19 +43,20 @@ class. \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}. +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}. +defining all but \method{__delitem__} will preclude only \method{pop} +and \method{popitem} from the full interface. -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}. +In addition to the four base methods, progessively more efficiency +comes with defining \method{__contains__()}, \method{__iter__()}, and +\method{iteritems()}. +Since the mixin has no knowledge of the subclass constructor, it +does not define \method{__init__()} or \method{copy()}. \end{classdesc} |