From: Brian Warner Date: Wed, 16 May 2012 23:50:57 +0000 (-0700) Subject: dictutil.DictOfSets: remove .union() method, it was misleading X-Git-Url: https://git.rkrishnan.org/specifications/%5B/%5D%20/flags/cyclelanguage?a=commitdiff_plain;h=cc366903cecb23b952fab69adb8f61f008597a45;p=tahoe-lafs%2Ftahoe-lafs.git 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 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: