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.
This commit is contained in:
Raymond Hettinger 2002-11-18 04:34:10 +00:00
parent 782d940866
commit 8ddc176e2e
3 changed files with 52 additions and 37 deletions

View file

@ -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}