]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
dictutil.DictOfSets: remove .union() method, it was misleading
authorBrian Warner <warner@lothar.com>
Wed, 16 May 2012 23:50:57 +0000 (16:50 -0700)
committerBrian Warner <warner@lothar.com>
Wed, 16 May 2012 23:55:09 +0000 (16:55 -0700)
Unlike set.union(), which returns a new set, DictOfSets.union() modified
the DictOfSets in-place. The name collision bit me when I changed some
code from using DictOfSets to a normal set, and expected that
set.union() would modify the set in-place. Since there was only one user
of DictOfSets.union, I figured it was safer to just get rid of it.

src/allmydata/test/test_util.py
src/allmydata/util/dictutil.py

index 575a7a493d2e3b19a06f13d3723b7e6ac58337e5..f6a6f2ff27e719f20bed9fdfeffb8482e4053757 100644 (file)
@@ -1119,16 +1119,13 @@ class DictUtil(unittest.TestCase):
         ds.discard(2, "c")
         self.failIf(2 in ds)
 
-        ds.union(1, ["a", "e"])
-        ds.union(3, ["f"])
-        self.failUnlessEqual(ds[1], set(["a","e"]))
-        self.failUnlessEqual(ds[3], set(["f"]))
+        ds.add(3, "f")
         ds2 = dictutil.DictOfSets()
         ds2.add(3, "f")
         ds2.add(3, "g")
         ds2.add(4, "h")
         ds.update(ds2)
-        self.failUnlessEqual(ds[1], set(["a","e"]))
+        self.failUnlessEqual(ds[1], set(["a"]))
         self.failUnlessEqual(ds[3], set(["f", "g"]))
         self.failUnlessEqual(ds[4], set(["h"]))
 
index 8de136f28ebdf1ff029b666f4b64f5fcf65512e0..7c03159c6ef1b3bd576333ff9bbf02ac630f481b 100644 (file)
@@ -40,15 +40,12 @@ class DictOfSets(dict):
         else:
             self[key] = set([value])
 
-    def union(self, key, values):
-        if key in self:
-            self[key].update(values)
-        else:
-            self[key] = set(values)
-
     def update(self, otherdictofsets):
-        for key, value in otherdictofsets.iteritems():
-            self.union(key, value)
+        for key, values in otherdictofsets.iteritems():
+            if key in self:
+                self[key].update(values)
+            else:
+                self[key] = set(values)
 
     def discard(self, key, value):
         if not key in self: