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 686261 - Add support for plugable argument coercion
Add support for plugable argument coercion
Status: RESOLVED OBSOLETE
Product: pygobject
Classification: Bindings
Component: introspection
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
: 693480 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2012-10-17 03:16 UTC by Simon Feltman
Modified: 2018-01-10 20:19 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Simon Feltman 2012-10-17 03:16:11 UTC
The idea is automatic coercion of arguments through gi exposed methods could support plugable from-python methods. This would allow the removal of explicit coercion in overrides that look like this:

    def get_cell_area(self, path, column=None):
        if not isinstance(path, Gtk.TreePath):
            path = TreePath(path)
        return super(TreeView, self).get_cell_area(path, column)


I propose a simple API using a decorator which could be something like the following:


class TreeIter(Gtk.TreeIter):
    @gi.register_coerce_from(tuple)
    @classmethod
    def from_tuple(cls, value):
        return ...

TreePath = override(TreePath)


An added benefit here is we also get an explicit "from_tuple" class method which can work as you would expect and can replace complex initializers with type checking in certain cases.
How this works internally can be left as an implementation detail but the proposed API should already provide enough information to make this happen.
Comment 1 Martin Pitt 2012-10-26 04:26:51 UTC
To be honest this looks a bit too magic to me, and it does not significantly help to reduce complexity. It's also much harder to debug new overrides that way. But don't consider that as a "no", it's just my initial gut feeling.
Comment 2 Simon Feltman 2013-02-17 10:33:51 UTC
*** Bug 693480 has been marked as a duplicate of this bug. ***
Comment 3 Simon Feltman 2013-02-17 11:33:10 UTC
For the record bug 693480 requests the same thing with a more explicit method: gi.register_custom_converters('GtkTreePath', from_, to_)

It will help reduce a bit of override code especially with the addition of: http://git.gnome.org/browse/pygobject/commit/?id=acef1d32

Even if code size is a wash, I think it is worth the added consistency in regards to it always working for any function taking a TreePath (or anything else a converter is registered for).
Comment 4 GNOME Infrastructure Team 2018-01-10 20:19:42 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/pygobject/issues/34.