OrderedDict: fix setitem bug #436974
authorZac Medico <zmedico@gentoo.org>
Tue, 2 Oct 2012 20:22:57 +0000 (13:22 -0700)
committerZac Medico <zmedico@gentoo.org>
Tue, 2 Oct 2012 20:22:57 +0000 (13:22 -0700)
This fixes some strange behavior triggered during fetch, which is only
observable with Python 2.6 since it doesn't have
collections.OrderedDict.

pym/portage/cache/mappings.py

index bc8ce9af80170b5a94bb866a1bb35601363b1b72..cd39a6ea166a61e90be36cdd64a691fa056f673c 100644 (file)
@@ -199,10 +199,10 @@ class OrderedDict(UserDict):
                return iter(self._order)
 
        def __setitem__(self, key, item):
-               if key in self:
-                       self._order.remove(key)
+               new_key = key not in self
                UserDict.__setitem__(self, key, item)
-               self._order.append(key)
+               if new_key:
+                       self._order.append(key)
 
        def __delitem__(self, key):
                UserDict.__delitem__(self, key)