Gentoo Archives: gentoo-commits

From: "Zac Medico (zmedico)" <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] portage r11473 - main/trunk/pym/portage/dbapi
Date: Sun, 24 Aug 2008 21:14:24
Message-Id: E1KXMuj-0002OD-FO@stork.gentoo.org
1 Author: zmedico
2 Date: 2008-08-24 21:14:20 +0000 (Sun, 24 Aug 2008)
3 New Revision: 11473
4
5 Modified:
6 main/trunk/pym/portage/dbapi/vartree.py
7 Log:
8 Fix _ObjectKey.__eq__() to account for potential hash collisions that would
9 break dict behavior. Thanks to Lucian Poston for spotting this.
10
11
12 Modified: main/trunk/pym/portage/dbapi/vartree.py
13 ===================================================================
14 --- main/trunk/pym/portage/dbapi/vartree.py 2008-08-24 19:50:47 UTC (rev 11472)
15 +++ main/trunk/pym/portage/dbapi/vartree.py 2008-08-24 21:14:20 UTC (rev 11473)
16 @@ -169,11 +169,12 @@
17 return hash(self._key)
18
19 def __eq__(self, other):
20 - if isinstance(other, self.__class__):
21 - other_key = other._key
22 - else:
23 - other_key = other
24 - return self._key == other_key
25 + if not isinstance(other, self.__class__):
26 + # Can't safely return True in this case since
27 + # if there is a hash collision then __eq__ needs
28 + # to be relied upon for correct dict behavior.
29 + return False
30 + return self._key == other._key
31
32 def _generate_object_key(self, object):
33 """