[Checkins] SVN: Sandbox/faassen/iface/src/iface/mapping. We also need to implement __eq__ to support the case where
Martijn Faassen
faassen at startifact.com
Wed Jan 6 16:44:24 EST 2010
Log message for revision 107754:
We also need to implement __eq__ to support the case where
we recreate the same map key.
Changed:
U Sandbox/faassen/iface/src/iface/mapping.py
U Sandbox/faassen/iface/src/iface/mapping.txt
-=-
Modified: Sandbox/faassen/iface/src/iface/mapping.py
===================================================================
--- Sandbox/faassen/iface/src/iface/mapping.py 2010-01-06 21:38:49 UTC (rev 107753)
+++ Sandbox/faassen/iface/src/iface/mapping.py 2010-01-06 21:44:23 UTC (rev 107754)
@@ -17,6 +17,9 @@
def __hash__(self):
return hash(self.key)
+ def __eq__(self, other):
+ return self.key == other.key
+
def __repr__(self):
return "<MapKey: %r>" % self.key
Modified: Sandbox/faassen/iface/src/iface/mapping.txt
===================================================================
--- Sandbox/faassen/iface/src/iface/mapping.txt 2010-01-06 21:38:49 UTC (rev 107753)
+++ Sandbox/faassen/iface/src/iface/mapping.txt 2010-01-06 21:44:23 UTC (rev 107754)
@@ -34,12 +34,22 @@
>>> map[a] = u'Value for A'
>>> map[a]
u'Value for A'
+
+If we recreate the MapKey (with the same parents, in this case none),
+we can still look up the same value::
+
+ >>> a_new = MapKey('a')
+ >>> map[a_new]
+ u'Value for A'
+
+Once we delete the entry we cannot look it up anymore::
+
>>> del map[a]
>>> map[a]
Traceback (most recent call last):
...
KeyError: <MapKey: 'a'>
-
+
We now register something for ``b``::
>>> map[b] = u'Value for B'
More information about the checkins
mailing list