Fix _ObjectKey.__eq__() to account for potential hash collisions that would
authorZac Medico <zmedico@gentoo.org>
Sun, 24 Aug 2008 21:14:20 +0000 (21:14 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 24 Aug 2008 21:14:20 +0000 (21:14 -0000)
break dict behavior. Thanks to Lucian Poston for spotting this.

svn path=/main/trunk/; revision=11473

pym/portage/dbapi/vartree.py

index 598845e0bb9128fc920f62c59ffe2c451e82a45c..2c030c13c73766f8e0b82f528d0cae769fb62dc6 100644 (file)
@@ -169,11 +169,12 @@ class LinkageMap(object):
                        return hash(self._key)
 
                def __eq__(self, other):
-                       if isinstance(other, self.__class__):
-                               other_key = other._key
-                       else:
-                               other_key = other
-                       return self._key == other_key
+                       if not isinstance(other, self.__class__):
+                               # Can't safely return True in this case since
+                               # if there is a hash collision then __eq__ needs
+                               # to be relied upon for correct dict behavior.
+                               return False
+                       return self._key == other._key
 
                def _generate_object_key(self, object):
                        """