GNOME Bugzilla – Bug 635172
When calling into overrides for some reason we are converting str("2") to int(2)
Last modified: 2012-02-10 09:34:17 UTC
Created attachment 174764 [details] Test case I encountered this problem when trying to add data received via DBus to a ListStore. python-dbus uses subclasses of built-in types such as int and str, which you cannot add to the liststore: Gtk-WARNING **: gtkliststore.c:660: Unable to convert from PyObject to gint
I remember someone else filing this but I can't find the bug. The issue is in PyGTK they have an override which can ask the store what type they are expecting. In PyGObject we do our best to guess by using the same routine that converts PyObject to regular types. The issue is the person might want to store a PyObject. I think I might need to break down and write the override even though it will slow down list insertion (and it already seems slow in the tests)
Created attachment 175738 [details] [review] [gi] handle subtypes when inserting into tree models * Often modules will give back basic types wrapped in a subtype. This is the case with D-Bus where you may want to keep some of the metadata around. More often than not, the developer is just looking to use the basetype. * This override checks the column type and handles basic types such as gchararrays, ints, longs, floats and doubles, converting them to their base types before sending them to the generic GI type marshaller. * More types may need to be supported but these are the common cases where apps break.
Finally got around to writing the patch. Let me know if this fixes your issues
Not sure if this issue is related to this bug, but when I subclass Gtk.ListStore like this: class MyStore(Gtk.ListStore): def __init__(self): Gtk.ListStore.__init__(int, str) I get: Traceback (most recent call last):
+ Trace 224952
class MyStore(Gtk.ListStore):
cls._setup_vfuncs(cls)
base._setup_vfuncs(impl)
vfunc_name()))
'str' object is not callable This should be added to the test suite.
(In reply to comment #4) > Not sure if this issue is related to this bug, but when I subclass > Gtk.ListStore like this: > > class MyStore(Gtk.ListStore): > > def __init__(self): - Gtk.ListStore.__init__(int, str) + Gtk.ListStore.__init__(self, int, str) or + super(MyStore, self).__init__(int, str) You are trying to call Gtk.ListStore.__init__ on a int instead of a ListStore. I guess we should do some type checking there. BTW. Can I commit this patch. Does it fix your issues?
Stupid mistake, still get the above error, though. The patch doesn't apply with latest master, could provide an updated patch, please.
looks like I already applied it. It still doesn't work? Can you post a more complete example?
I found the issue. Python thinks "2" is an int not string. I need to make the checks take that into account
This works with pygobject 3.1.0 (and presumably 3.0 as well). I also verified that print model[0][0], type(model[0][0]) (similar for the other entries) show the expected values.