From cc366903cecb23b952fab69adb8f61f008597a45 Mon Sep 17 00:00:00 2001
From: Brian Warner <warner@lothar.com>
Date: Wed, 16 May 2012 16:50:57 -0700
Subject: [PATCH] dictutil.DictOfSets: remove .union() method, it was
 misleading

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 |  7 ++-----
 src/allmydata/util/dictutil.py  | 13 +++++--------
 2 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/src/allmydata/test/test_util.py b/src/allmydata/test/test_util.py
index 575a7a49..f6a6f2ff 100644
--- a/src/allmydata/test/test_util.py
+++ b/src/allmydata/test/test_util.py
@@ -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"]))
 
diff --git a/src/allmydata/util/dictutil.py b/src/allmydata/util/dictutil.py
index 8de136f2..7c03159c 100644
--- a/src/allmydata/util/dictutil.py
+++ b/src/allmydata/util/dictutil.py
@@ -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:
-- 
2.45.2