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 652518 - Wrong GValue Type Conversion in PyGI - PyGObject
Wrong GValue Type Conversion in PyGI - PyGObject
Status: RESOLVED NOTABUG
Product: pygobject
Classification: Bindings
Component: introspection
2.28.x
Other Linux
: Normal critical
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2011-06-14 05:29 UTC by Mystilleef
Modified: 2011-06-17 16:14 UTC
See Also:
GNOME target: ---
GNOME version: 3.1/3.2



Description Mystilleef 2011-06-14 05:29:06 UTC
An API in PyGI telepathy-glib expects a guint32 value.
Unfortunately, PyGObject converts the value into a guint
which causes an error. Here's the specific error I'm
getting.

============================================================
Traceback (most recent call last):
  • File "buggy.py", line 73 in __create_async_cb
    account = am.create_account_finish(result)
  • File "/usr/lib/python2.7/site-packages/gi/types.py", line 44 in function
    return info.invoke(*args)
glib.GError: org.freedesktop.DBus.GLib.UnmappedError.McdAccountManagerError.Code0: Failed to set parameter: parameter keepalive-interval must be of type guint, not gint
============================================================

Tomeu Vizoso on the Telepathy mailing list suggests
PyGObject expose an API that helps with type conversion.
Something like this.

		uint32value = GValue(60, GValue.UInt32)

Does such an API already exist? Is there anything telepathy-
glib can do to avoid this problem? Also is there anything I
can do to work around the problem as a PyGI user?

Telepathy mailinglist discussion on the problem: http://lists.freedesktop.org/archives/telepathy/2011-June/005592.html
Comment 1 johnp 2011-06-14 15:09:47 UTC
Yes, GValues suck for dynamic bindings because in most cases applications are expecting a specific type but GValues give no indication of what type since they are containers that can hold any type.  In C it becomes a contract between the API and the programmer, e.g. they have to know what type by reading the documentation.  In Python we want to hide that from the user but we do expose an API for specifying GValue types.  It should only be used in overrides so I would implore Telepathy devs to ship overrides and not expose this behaviour to the user:

from gi.repository import GObject

value = GObject.Value()
value.init(GObject.TYPE_UNIT32)
value.set_uint(x)
Comment 2 Mystilleef 2011-06-14 22:39:26 UTC
Thanks for the suggestion.

I don't have GObject.TYPE_UNIT32 though. Is that in newer version of PyGObject. Where are those constants stored in older versions?
Comment 3 johnp 2011-06-15 21:00:12 UTC
oh, that is just a GObject.TYPE_UINT, 32 is implied.  The issue you were having was that the interface encoded a signed integer.
Comment 4 Mystilleef 2011-06-16 00:33:43 UTC
Thanks John, that fixed my problem. 

I'm guessing this is not a bug in PyGObject then and can be closed.