From: Daira Hopwood Date: Thu, 5 Sep 2013 16:53:39 +0000 (+0100) Subject: Thu May 17 00:55:09 BST 2012 Brian Warner X-Git-Url: https://git.rkrishnan.org/pf/content/simplejson/install.html?a=commitdiff_plain;h=93e5813b1b7f9ee20cfcdd0809b7ce12ad4b7738;p=tahoe-lafs%2Ftahoe-lafs.git Thu May 17 00:55:09 BST 2012 Brian Warner * 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. --- diff --git a/src/allmydata/test/test_util.py b/src/allmydata/test/test_util.py index 54ef2551..fcbc806c 100644 --- a/src/allmydata/test/test_util.py +++ b/src/allmydata/test/test_util.py @@ -1110,16 +1110,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: