##// END OF EJS Templates
Use ternary operator for callback registration
Jonathan Frederic -
Show More
@@ -50,10 +50,7 b' class EventfulDict(dict):'
50 50 The callback should have a signature of callback(key, value). The
51 51 callback should return a boolean True if the additon should be
52 52 canceled, False or None otherwise."""
53 if callable(callback):
54 self._add_callback = callback
55 else:
56 self._add_callback = _void
53 self._add_callback = callback if callable(callback) else _void
57 54
58 55 def on_del(self, callback):
59 56 """Register a callback for when an item is deleted from the dict.
@@ -66,11 +63,8 b' class EventfulDict(dict):'
66 63 The callback should have a signature of callback(key). The
67 64 callback should return a boolean True if the deletion should be
68 65 canceled, False or None otherwise."""
69 if callable(callback):
70 self._del_callback = callback
71 else:
72 self._del_callback = _void
73
66 self._del_callback = callback if callable(callback) else _void
67
74 68 def on_set(self, callback):
75 69 """Register a callback for when an item is changed in the dict.
76 70
@@ -82,11 +76,8 b' class EventfulDict(dict):'
82 76 The callback should have a signature of callback(key, value). The
83 77 callback should return a boolean True if the change should be
84 78 canceled, False or None otherwise."""
85 if callable(callback):
86 self._set_callback = callback
87 else:
88 self._set_callback = _void
89
79 self._set_callback = callback if callable(callback) else _void
80
90 81 def pop(self, key):
91 82 """Returns the value of an item in the dictionary and then deletes the
92 83 item from the dictionary."""
@@ -182,11 +173,8 b' class EventfulList(list):'
182 173 The callback should have a signature of callback(index, value). The
183 174 callback should return a boolean True if the insertion should be
184 175 canceled, False or None otherwise."""
185 if callable(callback):
186 self._insert_callback = callback
187 else:
188 self._insert_callback = _void
189
176 self._insert_callback = callback if callable(callback) else _void
177
190 178 def on_del(self, callback):
191 179 """Register a callback for item deletion.
192 180
@@ -198,10 +186,7 b' class EventfulList(list):'
198 186 The callback should have a signature of callback(index). The
199 187 callback should return a boolean True if the deletion should be
200 188 canceled, False or None otherwise."""
201 if callable(callback):
202 self._del_callback = callback
203 else:
204 self._del_callback = _void
189 self._del_callback = callback if callable(callback) else _void
205 190
206 191 def on_set(self, callback):
207 192 """Register a callback for items are set.
@@ -215,10 +200,7 b' class EventfulList(list):'
215 200 The callback should have a signature of callback(index, value). The
216 201 callback should return a boolean True if the set should be
217 202 canceled, False or None otherwise."""
218 if callable(callback):
219 self._set_callback = callback
220 else:
221 self._set_callback = _void
203 self._set_callback = callback if callable(callback) else _void
222 204
223 205 def on_reverse(self, callback):
224 206 """Register a callback for list reversal.
@@ -228,10 +210,7 b' class EventfulList(list):'
228 210 The callback should have a signature of callback(). The
229 211 callback should return a boolean True if the reverse should be
230 212 canceled, False or None otherwise."""
231 if callable(callback):
232 self._reverse_callback = callback
233 else:
234 self._reverse_callback = _void
213 self._reverse_callback = callback if callable(callback) else _void
235 214
236 215 def on_sort(self, callback):
237 216 """Register a callback for sortting of the list.
@@ -242,10 +221,7 b' class EventfulList(list):'
242 221 method or `callback(*pargs, **kwargs)` as a catch all. The callback
243 222 should return a boolean True if the reverse should be canceled,
244 223 False or None otherwise."""
245 if callable(callback):
246 self._sort_callback = callback
247 else:
248 self._sort_callback = _void
224 self._sort_callback = callback if callable(callback) else _void
249 225
250 226 def append(self, x):
251 227 """Add an item to the end of the list."""
General Comments 0
You need to be logged in to leave comments. Login now