GNOME Bugzilla – Bug 694431
Add overrides helper for stripping boolean returns
Last modified: 2013-02-27 22:03:42 UTC
There are a great many places where overrides strip away boolean values from the front of a return tuple: def iter_children(self, aiter): success, child_iter = super(TreeModel, self).iter_children(aiter) if success: return child_iter We could simplify this with a helper: iter_children = strip_boolean_result(Gtk.TreeModel.iter_children) For functions which conditionally return something other than None when the boolean result is False, the helper could be supplied an optional arg: iter_children = strip_boolean_result(Gtk.TreeModel.iter_children, EmptyIter())
Indeed, that would clean up the overrides a bit. I'm not totally happy about them, as we have lots of API with that style without an override, so we are rather inconsistent in that regard. But that's of course unrelated to cleaning up the existing ones.
Hah, after adding this wrapper and converting the Gtk overrides, I noticed that Gdk already has had such a thing: def _gsuccess_mask(func): def cull_success(*args): result = func(*args) success = result[0] if not success: return None else: if len(result) == 2: return result[1] else: return result[1:] return cull_success I'll clean this up, too.
Quite an improvement :-) 3 files changed, 53 insertions(+), 152 deletions(-) http://git.gnome.org/browse/pygobject/commit/?id=4f6ebcfe0605a7a593d
nicely done!