Python bindings: super doesn't work
In python, the standard way to chain-call a parent method is to use super
. But for some reason super
doesn't work with the vast majority of Gtk methods. See this demo:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class MyWindow(Gtk.Window):
def __init__(self):
super().__init__() # Works here
def do_get_preferred_width(self):
# TypeError: Gtk.Widget.get_preferred_width() takes exactly 1 argument (0 given)
return super().do_get_preferred_width()
window = MyWindow()
window.show()
window.connect('destroy', Gtk.main_quit)
Gtk.main()
It's as if every method is a staticmethod
; the self
argument isn't passed in. And here's the kicker, passing it in manually causes the method to call itself!
return super().do_get_preferred_width(self)
# RecursionError: maximum recursion depth exceeded while calling a Python object