[pygi] Improve handling of subclasses without __gtype_name__



commit 1561d2977691f1cb8684f183a2e274c47960d931
Author: Tomeu Vizoso <tomeu vizoso collabora co uk>
Date:   Mon May 24 18:48:10 2010 +0200

    Improve handling of subclasses without __gtype_name__
    
    Gives a better message at type registration.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=616849

 gi/gimodule.c    |    9 +++++++++
 tests/test_gi.py |   13 ++++++++++++-
 2 files changed, 21 insertions(+), 1 deletions(-)
---
diff --git a/gi/gimodule.c b/gi/gimodule.c
index 7453139..e0ea1e8 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -170,6 +170,15 @@ _wrap_pyg_hook_up_vfunc_implementation (PyObject *self, PyObject *args)
         GTypeInstance *implementor_iface_class;
         implementor_iface_class = g_type_interface_peek(implementor_class,
                                                         ancestor_g_type);
+        if (implementor_iface_class == NULL) {
+            g_type_class_unref (implementor_class);
+            PyErr_Format (PyExc_RuntimeError,
+                    "Couldn't find GType of implementor of interface %s. "
+                    "Forgot to set __gtype_name__?",
+                    g_type_name (ancestor_g_type));
+            return NULL;
+        }
+
         g_type_class_unref (implementor_class);
         implementor_class = implementor_iface_class;
 
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 9b19155..7158e74 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -12,6 +12,7 @@ from datetime import datetime
 import sys
 sys.path.insert(0, "../")
 
+import gobject
 from gi.repository import GIMarshallingTests
 
 
@@ -1495,7 +1496,6 @@ class TestPythonGObject(unittest.TestCase):
 
     def test_dynamic_module(self):
         from gi.module import DynamicGObjectModule
-        import gobject
         self.assertTrue(isinstance(GObject, DynamicGObjectModule))
         # compare the same enum from both the pygobject attrs and gi GObject attrs
         self.assertEquals(GObject.SIGNAL_ACTION, GObject.SignalFlags.ACTION)
@@ -1549,6 +1549,17 @@ class TestInterfaces(unittest.TestCase):
         GIMarshallingTests.test_interface_test_int8_in(instance, 42)
         self.assertEquals(instance.val, 42)
 
+        def define_implementor_without_gtype():
+            class TestInterfaceImpl(gobject.GObject, GIMarshallingTests.Interface):
+                def __init__(self):
+                    gobject.GObject.__init__(self)
+                    self.val = None
+
+                def do_test_int8_in(self, int8):
+                    self.val = int8
+        self.assertRaises(RuntimeError, define_implementor_without_gtype)
+
+
 class TestOverrides(unittest.TestCase):
 
     def test_constant(self):



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