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 749680 - super() is not called
super() is not called
Status: RESOLVED OBSOLETE
Product: pygobject
Classification: Bindings
Component: introspection
3.14.x
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2015-05-21 13:04 UTC by Tobias Mueller
Modified: 2018-01-10 20:49 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Tobias Mueller 2015-05-21 13:04:11 UTC
My test case is:

#!/usr/bin/env python

from gi.repository import Gtk

class Super(object):
    def __init__(self):
        print("Super here")
        super(Super, self).__init__()


class Side(Super):
    def __init__(self):
        print("Side here")
        super(Side, self).__init__()

#class Child(Side, Gtk.Window):
class Child(Gtk.Window, Side):
    def __init__(self):
        print("Child here")
        super(Child, self).__init__()

Super()

print('-----')
Side()

print('-----')
Child()



I have expected that Side's constructor is called as well as Super's.  If I take care of the order of the base classes, then it works, but I didn't expect having to do that.



I didn't understand bug 315079, bug 351566 nor bug 710646, so this might very well be a duplicate. Although I am missing a concise test case and in my example.
Comment 1 Christoph Reiter (lazka) 2017-03-29 16:05:07 UTC
A similar thing can be seen with the list built-in type:

class Foo(object):
    def __init__(self, *args, **kwargs):
        print("Foo")
        super(Foo, self).__init__(*args, **kwargs)


class A(list, Foo):
    def __init__(self, *args, **kwargs):
        print("A")
        super(A, self).__init__(*args, **kwargs)

A()

-----------

It's because tp_init doesn't chain up using super.

Here is an example: https://pythonextensionpatterns.readthedocs.io/en/latest/super_call.html

It might be easier to override __init__ for GObject.Object and call super in Python (super(gi._gobject.GObject, self)...)
Comment 2 Christoph Reiter (lazka) 2017-03-30 07:39:21 UTC
There also exists a python bug regarding the list behavior https://bugs.python.org/issue8733
Comment 3 GNOME Infrastructure Team 2018-01-10 20:49:42 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/pygobject/issues/100.