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 635172 - When calling into overrides for some reason we are converting str("2") to int(2)
When calling into overrides for some reason we are converting str("2") to int(2)
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: introspection
Git master
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2010-11-18 12:00 UTC by Sebastian Pölsterl
Modified: 2012-02-10 09:34 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Test case (185 bytes, text/plain)
2010-11-18 12:00 UTC, Sebastian Pölsterl
  Details
[gi] handle subtypes when inserting into tree models (3.87 KB, patch)
2010-12-02 21:47 UTC, johnp
committed Details | Review

Description Sebastian Pölsterl 2010-11-18 12:00:47 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
Comment 1 johnp 2010-11-18 17:04:22 UTC
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)
Comment 2 johnp 2010-12-02 21:47:50 UTC
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.
Comment 3 johnp 2010-12-02 21:48:35 UTC
Finally got around to writing the patch. Let me know if this fixes your issues
Comment 4 Sebastian Pölsterl 2010-12-03 11:39:43 UTC
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):
  • File "test_liststore_subclass.py", line 3 in <module>
    class MyStore(Gtk.ListStore):
  • File "/opt/gnome3/lib/python2.6/site-packages/gi/types.py", line 174 in __init__
    cls._setup_vfuncs(cls)
  • File "/opt/gnome3/lib/python2.6/site-packages/gi/types.py", line 134 in _setup_vfuncs
    base._setup_vfuncs(impl)
  • File "/opt/gnome3/lib/python2.6/site-packages/gi/types.py", line 134 in _setup_vfuncs
    base._setup_vfuncs(impl)
  • File "/opt/gnome3/lib/python2.6/site-packages/gi/types.py", line 110 in _setup_vfuncs
    vfunc_name()))
TypeError: Error when calling the metaclass bases
    'str' object is not callable

This should be added to the test suite.
Comment 5 johnp 2010-12-07 18:44:55 UTC
(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?
Comment 6 Sebastian Pölsterl 2010-12-08 09:26:20 UTC
Stupid mistake, still get the above error, though.

The patch doesn't apply with latest master, could provide an updated patch, please.
Comment 7 johnp 2010-12-08 17:40:32 UTC
looks like I already applied it.  It still doesn't work?  Can you post a more complete example?
Comment 8 johnp 2010-12-08 21:13:44 UTC
I found the issue.  Python thinks "2" is an int not string.  I need to make the checks take that into account
Comment 9 Martin Pitt 2012-02-10 09:34:17 UTC
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.