[pygobject/fix-gio-proxy-init] gtktemplate: only call the custom init hook if the class has it. Fixes #267



commit d75a6c178c68b075c808af2ed0372247b28ea2b5
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Mon Nov 26 09:06:35 2018 +0100

    gtktemplate: only call the custom init hook if the class has it. Fixes #267
    
    Otherwise we call into __getattr__ implementations of subclasses, like the
    overrides for Gio.DBusProxy. This is particularly bad because the instance
    isn't initialized at that point yet.

 gi/gimodule.c       | 2 +-
 tests/test_gdbus.py | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/gi/gimodule.c b/gi/gimodule.c
index 3a616165..e25583e5 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -1066,7 +1066,7 @@ pygobject__g_instance_init(GTypeInstance   *instance,
     }
 
     /* XXX: used for Gtk.Template */
-    if (PyObject_HasAttrString (wrapper, "__dontuse_ginstance_init__")) {
+    if (PyObject_HasAttrString ((PyObject*) Py_TYPE (wrapper), "__dontuse_ginstance_init__")) {
         result = PyObject_CallMethod (wrapper, "__dontuse_ginstance_init__", NULL);
         if (result == NULL)
             PyErr_Print ();
diff --git a/tests/test_gdbus.py b/tests/test_gdbus.py
index 18315afa..6e38abe3 100644
--- a/tests/test_gdbus.py
+++ b/tests/test_gdbus.py
@@ -248,3 +248,10 @@ class TestGDBusClient(unittest.TestCase):
 
         self.assertTrue(isinstance(data['error'], Exception))
         self.assertTrue('InvalidArgs' in str(data['error']), str(data['error']))
+
+    def test_instantiate_custom_proxy(self):
+        class SomeProxy(Gio.DBusProxy):
+            def __init__(self):
+                Gio.DBusProxy.__init__(self)
+
+        SomeProxy()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]