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 654859 - Can't construct GVariant from format string in Python
Can't construct GVariant from format string in Python
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: general
2.28.x
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2011-07-18 16:54 UTC by Eitan Isaacson
Modified: 2012-04-23 17:03 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Eitan Isaacson 2011-07-18 16:54:53 UTC
It seems that commit e61fa51 (bug #646635) adds annotation that skips g_variant_new. Not sure why. We depend on constructing GVariants from format strings in Caribou (bug #654852).

This may be intentional. If it is, what is the alternative API for this functionality?
Comment 1 Matthias Clasen 2011-07-19 12:02:16 UTC
Add relevant people to CC
Comment 2 Giovanni Campagna 2011-07-20 11:34:32 UTC
g_variant_new uses varargs, so it cannot be accessed from python (or any dynamic introspected language). GLib.Variant constructor in Python is an override, so I think the bug is in pygobject.
Comment 3 Dan Winship 2011-07-26 14:55:50 UTC
danw@desktop:pygobject (pygobject-2-28)> cat /tmp/foo.py
from gi.repository import GLib

GLib.Variant('b', False)

danw@desktop:pygobject (pygobject-2-28)> jhbuild run python /tmp/foo.py
Traceback (most recent call last):
  • File "/tmp/foo.py", line 3 in <module>
    GLib.Variant('b', False)
  • File "/opt/jhbuild/lib64/python2.7/site-packages/gi/overrides/GLib.py", line 181 in __new__
    (v, rest_format, _) = creator._create(format_string, [value])
  • File "/opt/jhbuild/lib64/python2.7/site-packages/gi/overrides/GLib.py", line 79 in _create
    v = constructor(args[0])
  • File "/opt/jhbuild/lib64/python2.7/site-packages/gi/types.py", line 68 in constructor
    return info.invoke(cls, *args)
TypeError: cannot create 'Variant' instances

Comment 4 johnp 2011-07-26 15:53:42 UTC
(In reply to comment #3)
> danw@desktop:pygobject (pygobject-2-28)> cat /tmp/foo.py
> from gi.repository import GLib
> 
> GLib.Variant('b', False)
> 
> danw@desktop:pygobject (pygobject-2-28)> jhbuild run python /tmp/foo.py
> Traceback (most recent call last):
> 

You are using to new a version of GLib and GLib Introspection.  This was fixed in master and I am in the process of making master parallel installable with pygobject-2.28 (with introspection turned off).  What is in master will be what ships with Gnome-3.2
Comment 5 johnp 2011-07-26 15:59:14 UTC
I was a bit unclear with my above comment.

What happened was GLib Introspection decided to mark Variants as fundamental types instead of foreign types which means when using a newer typelib generated by GObject Introspection, pygobject-2.28 fails to convert the Variant to the correct python wrapper because the foreign code path is not executed.  We added explicit support for Variants in pygobject's master branch to fix this on our end.  The support was not finished for 2.28 and for the most point unless it seems like we won't release in time for GNOME 3.2, I don't want to add the code to a stable branch.
Comment 6 Dan Winship 2011-07-26 16:03:46 UTC
should jhbuild be switched to master then? (It's currently building pygobject-2-28 for GNOME 3.2)
Comment 7 johnp 2011-07-28 19:09:00 UTC
It needs to build both to support static bindings and for that to happen the parallel install stuff needs to be approved.  Tomeu wants me to post to the relevant python mailing lists first since it complicates how we distribute.  The other option would be to rename the module gi3 but that would be a pain for current Introspection apps.
Comment 8 Dan Winship 2011-08-04 17:48:52 UTC
(working around this in caribou for now by just not using gvariant)
Comment 9 Colin Walters 2011-08-04 21:35:15 UTC
Hmm; so what changed here is that g-i stopped exporting GVariant as foreign?

Can't it be special cased in the pygobject-2-28 branch?
Comment 10 Giovanni Campagna 2011-08-05 13:34:48 UTC
(In reply to comment #9)
> Hmm; so what changed here is that g-i stopped exporting GVariant as foreign?
> 
> Can't it be special cased in the pygobject-2-28 branch?

We regenerated glib-2.0.c from glib sources (which never marked GVariant as (foreign)).
Comment 11 Martin Pitt 2012-04-23 17:03:38 UTC
The overrides for GLib.Variant are covered by the tests, and work well. This does not affect pygobject 3.0 and 3.2, and we don't support GI in the old 2.28 branch (use the static bindings there), so I'm closing this.

Thanks!