GNOME Bugzilla – Bug 778290
Gio.ListStore.insert_sorted() broken
Last modified: 2018-04-20 08:24:55 UTC
When using Gio.ListStore.insert_sorted() with a GLib.CompareDataFunc, liststore pass int as args to sort function instead of GObject. GLib.CompareDataFunc(a, b, user_data) Parameters: a (object or None) – a value b (object or None) – a value to compare with user_data (object or None) – user data Actual result: $ python liststore.py 12028736 12028768 #!/usr/bin/env python3 from gi.repository import Gio, GObject class Item(GObject.GObject): name = GObject.Property(type=str, default='') def sort(row1, row2): print(row1, row2) return 0 model = Gio.ListStore() item1 = Item() item1.set_property('name', 'plop') item2 = Item() item2.set_property('name', 'plop') model.insert_sorted(item1, sort) model.insert_sorted(item2, sort)
'ints' in this case are pointers to GObjects. The GCompareFunc is part of GLib, so it has no idea what "GObject" is, and we cannot annotate it. Maybe pygobject can provide an override for that, since it knows that the sorting function is going to get two GObject instances, but that may require some CPython trickery. Let's re-assign this to pygobject; if there's no way to deal with this at the Python level, then we may need to add new API to GListStore: - a new comparison function, with correctly typed arguments - a new insert_sorted() variant that uses the new comparison function
The code in bug 759646 could help with adding an override for this.
-- 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/130.
I've created a MR for this: https://gitlab.gnome.org/GNOME/pygobject/merge_requests/61