After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 694431 - Add overrides helper for stripping boolean returns
Add overrides helper for stripping boolean returns
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: introspection
unspecified
Other Linux
: Low enhancement
: ---
Assigned To: Martin Pitt
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2013-02-22 10:30 UTC by Simon Feltman
Modified: 2013-02-27 22:03 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Simon Feltman 2013-02-22 10:30:18 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())
Comment 1 Martin Pitt 2013-02-22 10:36:16 UTC
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.
Comment 2 Martin Pitt 2013-02-27 17:24:25 UTC
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.
Comment 3 Martin Pitt 2013-02-27 17:32:27 UTC
Quite an improvement :-)

 3 files changed, 53 insertions(+), 152 deletions(-)

http://git.gnome.org/browse/pygobject/commit/?id=4f6ebcfe0605a7a593d
Comment 4 Simon Feltman 2013-02-27 22:03:42 UTC
nicely done!