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 711487 - GObject constructor for Gtk classes silently accepts and ignores positional arguments
GObject constructor for Gtk classes silently accepts and ignores positional a...
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: introspection
3.10.x
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2013-11-05 13:35 UTC by Martin Pitt
Modified: 2013-11-06 22:53 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Martin Pitt 2013-11-05 13:35:53 UTC
Spotted in https://bugs.launchpad.net/ubuntu/+source/pygobject/+bug/1248152: The reporter tried to create a FileChooserWidget like this:

  chooser = Gtk.FileChooserWidget(self,               Gtk.FileChooserAction.SELECT_FOLDER)

the "self" does not make any sense there, but the intended meaning was

  chooser = Gtk.FileChooserWidget(Gtk.FileChooserAction.SELECT_FOLDER)

this silently succeeds, but does not have any actual effect. In fact, it seems that this is now the case for every widget which doesn't have an override:

 python3 -c 'from gi.repository import Gtk; w = Gtk.Button(2, 3, 4); print(w)'
<Button object at 0x7eff00e55780 (GtkButton at 0x129b180)>

So it seems you can specify arbitrary arguments now which get silently ignored. In the past this used to raise a meaningful exception, we should restore that to avoid confusion.
Comment 1 Martin Pitt 2013-11-05 13:52:38 UTC
This might be specific to Gtk. It works fine with other classes:

$ python3 -c 'from gi.repository import Gio; o = Gio.Application(1); print(o)' 
Traceback (most recent call last):
  • File "<string>", line 1 in <module>
TypeError: GObject.__init__() takes exactly 0 arguments (1 given)

$ python3 -c 'from gi.repository import GUdev; o = GUdev.Client(2, 3); print(o)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: GObject.__init__() takes exactly 0 arguments (2 given)
Comment 2 Martin Pitt 2013-11-05 14:11:32 UTC
Ignore the Gtk.Button example in the description, Gtk.Button does have an overridden constructor. I wrote a test case using Gtk.Widget and Gtk.Container (have overrides, but no overridden ctor) and Gtk.FileChooserWidget (no override at all).
Comment 3 Martin Pitt 2013-11-05 14:18:25 UTC
This is because we have overrides for the parent classes, in particular Gtk.Bin and Gtk.Window. These don't do sufficient type checking, and they should ideally not apply to all subclasses.
Comment 4 Martin Pitt 2013-11-05 14:31:46 UTC
This can't be fixed fully as long as we still support the old PyGTK style constructors, but this should at least avoid most pitfalls:

https://git.gnome.org/browse/pygobject/commit/?id=7193f050
Comment 5 Simon Feltman 2013-11-06 22:49:08 UTC
(In reply to comment #0)
> ...
> In the past this used to raise a meaningful exception, we should restore that
> to avoid confusion.

I'm not sure what changed this, but there is a patch in bug 705810 which should fix this for all cases (instead of needing overrides):

See pygobject.c:pygobject_init in this patch:
https://bugzilla.gnome.org/show_bug.cgi?id=705810#c13
Comment 6 Simon Feltman 2013-11-06 22:53:37 UTC
(In reply to comment #5)
> I'm not sure what changed this, but there is a patch in bug 705810 which should
> fix this for all cases (instead of needing overrides):

Ah, never mind, it looks like those existing overrides don't accept *args anyhow. However, the patch mentioned fixes the case where *args are passed to a non-overridden GObject class (and subsequently ignored).