GNOME Bugzilla – Bug 686261
Add support for plugable argument coercion
Last modified: 2018-01-10 20:19:42 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.
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.
*** Bug 693480 has been marked as a duplicate of this bug. ***
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).
-- 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.