Browse Source

Override keys() with a function, not an attribute

By mistake keys function has been overriden by a value.

Change-Id: I713bddcfb66c4835d477972ece7e0983d263377f
Closes-Bug: #1666913
Georgy Kibardin 2 years ago
parent
commit
b8e2606daf
2 changed files with 9 additions and 3 deletions
  1. 6
    0
      nailgun/nailgun/test/unit/test_uniondict.py
  2. 3
    3
      nailgun/nailgun/utils/uniondict.py

+ 6
- 0
nailgun/nailgun/test/unit/test_uniondict.py View File

@@ -103,3 +103,9 @@ f: 6"""
103 103
     def test_repr(self):
104 104
         d = UnionDict(self.D1, self.D2, self.D3)
105 105
         self.assertEquals(eval(repr(d)), self.D)
106
+
107
+    def test_keys(self):
108
+        ud = UnionDict({'a': 1, 'b': 2, 'c': 3},
109
+                       {'b': 2, 'c': 3, 'd': 4},
110
+                       {'e': 5})
111
+        self.assertEquals(ud.keys(), {'a', 'b', 'c', 'd', 'e'})

+ 3
- 3
nailgun/nailgun/utils/uniondict.py View File

@@ -31,7 +31,7 @@ class UnionDict(collections.Mapping):
31 31
 
32 32
         self.dicts = list(dicts)
33 33
         self.dicts.reverse()
34
-        self.keys = set(itertools.chain.from_iterable(dicts))
34
+        self.keys = lambda: set(itertools.chain.from_iterable(dicts))
35 35
 
36 36
     def __getitem__(self, key):
37 37
         values = []
@@ -54,10 +54,10 @@ class UnionDict(collections.Mapping):
54 54
         return UnionDict(*values)
55 55
 
56 56
     def __iter__(self):
57
-        return iter(self.keys)
57
+        return iter(self.keys())
58 58
 
59 59
     def __len__(self):
60
-        return len(self.keys)
60
+        return len(self.keys())
61 61
 
62 62
     def __repr__(self):
63 63
         items = ['{!r}: {!r}'.format(k, v) for k, v in self.items()]

Loading…
Cancel
Save