GNOME Bugzilla – Bug 351566
super() calls do not work in __init__
Last modified: 2012-04-21 14:14:49 UTC
The following code prints nothing: --- import gtk class WidgetMixin(object): def __init__(self): super(WidgetMixin, self).__init__() print "Called WidgetMixin.__init__." class MixedInLabel(gtk.Label, WidgetMixin): def __init__(self): super(MixedInLabel, self).__init__() if __name__ == "__main__": MixedInLabel() --- When it should print "Called WidgetMixin.__init__". This may come from a common misinterpretation of super (described at http://fuhm.net/super-harmful/): "One big problem with 'super' is that it sounds like it will cause the superclass's copy of the method to be called. This is simply not the case, it causes the next method in the MRO to be called. People omit calls to super(...).__init__ if the only superclass is 'object', as, after all, object.__init__ doesn't do anything! However, this is very incorrect. Doing so will cause other classes' __init__ methods to not be called." I am marking this major because it makes mixins near-useless for PyGTK, and certainly is not the behavior one expects calling super().
*** This bug has been marked as a duplicate of 315079 ***
This is a different bug, not a dup of bug 315079. #315079 is a special case for do_xxx methods, this relates to tp_init and the need to chain to a parent class using MRO. The two bugs have completely different solutions.
I was looking at this bug, but it is relatively difficult to fix: 1. It requires going to pygobject_constructv and chaining to parent constructor using a real super object (using PySuper_Type.tp_new (...), calling __init__ method on it, passing the class as first argument, etc..) 2. It requires that pygobject_constructv receives the python class as parameter, like in regular python code => API changes, code generator changes. Personally I don't have time to fix this, but patches are welcome.
*** Bug 554443 has been marked as a duplicate of this bug. ***
Thanks for taking the time to report this bug. However, this bug report applies to a PyGObject version that is too old and not supported anymore. PyGObject developers are no longer working on static bindings, so unfortunately there will not be any bug fixes for the version this report applies to. By upgrading to a newer version of PyGObject you could receive bug fixes and new functionality. Please feel free to reopen this bug if the problem still occurs with a newer version of PyGObject.