[Checkins]
SVN: zc.dict/branches/satchit-ordered-dict/src/zc/dict/ordered.
removed restriction on the `update` method to accept only
OrderedDict.
Satchidanand Haridas
satchit at zope.com
Sun Dec 16 01:22:50 EST 2007
Log message for revision 82294:
removed restriction on the `update` method to accept only OrderedDict.
Changed:
U zc.dict/branches/satchit-ordered-dict/src/zc/dict/ordered.py
U zc.dict/branches/satchit-ordered-dict/src/zc/dict/ordered.txt
-=-
Modified: zc.dict/branches/satchit-ordered-dict/src/zc/dict/ordered.py
===================================================================
--- zc.dict/branches/satchit-ordered-dict/src/zc/dict/ordered.py 2007-12-16 06:07:50 UTC (rev 82293)
+++ zc.dict/branches/satchit-ordered-dict/src/zc/dict/ordered.py 2007-12-16 06:22:49 UTC (rev 82294)
@@ -94,8 +94,6 @@
self._order = new_order
def update(self, other):
- if other.__class__ != OrderedDict:
- raise TypeError('argument must be an OrderedDict.')
for k, v in other.iteritems():
self[k] = v
Modified: zc.dict/branches/satchit-ordered-dict/src/zc/dict/ordered.txt
===================================================================
--- zc.dict/branches/satchit-ordered-dict/src/zc/dict/ordered.txt 2007-12-16 06:07:50 UTC (rev 82293)
+++ zc.dict/branches/satchit-ordered-dict/src/zc/dict/ordered.txt 2007-12-16 06:22:49 UTC (rev 82294)
@@ -72,7 +72,8 @@
>>> c.items() == d.items()
True
-The `update` method only accepts OrderedDict as a parameter.
+The `update` method is also provided. If it is provided with an OrderedDict,
+then the new elements are added in the same order as in the argument.
>>> d2 = OrderedDict()
>>> d2['five'] = 'Five'
@@ -82,15 +83,9 @@
[('two', 'Two'), ('one', 'One'), ('five', 'Five'), ('six', 'Six')]
-The method returns an error if the argument is not an OrderedDict
+But if the argument is a regular Dict, then the order of the newly added
+elements in the resulting OrderedDict object cannot be guaranteed.
- >>> from zc.dict import Dict
- >>> d.update(Dict({'a': 'a'}))
- Traceback (most recent call last):
- ...
- TypeError: argument must be an OrderedDict.
-
-
clear removes all the keys from the dict:
>>> d.clear()
More information about the Checkins
mailing list