[pygi] Dont force subclasses to implement all virtual methods of their bases



commit 1d9c6b6d76a3e27f66e6f0cfc7b16c5191e4fc22
Author: Tomeu Vizoso <tomeu sugarlabs org>
Date:   Tue Apr 27 10:24:35 2010 +0200

    Dont force subclasses to implement all virtual methods of their bases
    
    https://bugzilla.gnome.org/show_bug.cgi?id=616674

 gi/types.py      |    4 ++--
 tests/test_gi.py |   15 +++++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/gi/types.py b/gi/types.py
index 21ff79e..78b126d 100644
--- a/gi/types.py
+++ b/gi/types.py
@@ -99,12 +99,12 @@ class MetaClassHelper(object):
                 continue
             for vfunc_info in base.__info__.get_vfuncs():
                 vfunc = getattr(cls, 'do_' + vfunc_info.get_name(), None)
-                if vfunc is None:
+                if vfunc is None and isinstance(base.__info__, InterfaceInfo):
                     raise TypeError('Class implementing %s.%s should implement '
                             'the method do_%s()' % (base.__info__.get_namespace(),
                                                     base.__info__.get_name(),
                                                     vfunc_info.get_name()))
-                else:
+                elif vfunc is not None:
                     hook_up_vfunc_implementation(vfunc_info, cls.__gtype__,
                                                  vfunc)
 
diff --git a/tests/test_gi.py b/tests/test_gi.py
index d630398..2c596be 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -1409,6 +1409,9 @@ class TestPythonGObject(unittest.TestCase):
         def do_method_int8_in(self, int8):
             self.val = int8
 
+        def do_method_with_default_implementation(self, int8):
+            self.props.int = int8 * 2
+
     def test_object(self):
         self.assertTrue(issubclass(self.Object, GIMarshallingTests.Object))
 
@@ -1423,6 +1426,18 @@ class TestPythonGObject(unittest.TestCase):
         object_.method_int8_in(84)
         self.assertEqual(object_.val, 84)
 
+        object_.method_with_default_implementation(42)
+        self.assertEqual(object_.val, 84)
+
+        class ObjectWithoutVFunc(GIMarshallingTests.Object):
+            __gtype_name__ = 'ObjectWithoutVFunc'
+
+            def __init__(self, int):
+                GIMarshallingTests.Object.__init__(self)
+
+        object_ = ObjectWithoutVFunc(int = 42)
+        object_.method_with_default_implementation(84)
+        self.assertEqual(object_.props.int, 84)
 
 class TestMultiOutputArgs(unittest.TestCase):
 



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