[pygobject] Always register a new GType when a GObject class is subclassed
- From: Steve Frécinaux <sfre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Always register a new GType when a GObject class is subclassed
- Date: Tue, 18 Jan 2011 12:11:03 +0000 (UTC)
commit 84d6142c14a7ebfb7284d3db52e14d3393f93905
Author: Steve Frécinaux <code istique net>
Date: Mon Jan 17 18:57:58 2011 +0100
Always register a new GType when a GObject class is subclassed
This patch makes the GType <-> python mapping much more predictible,
and fixes the bug caused by overriding methods without specifying a
__gtype_name__ member in the subclass, and makes type_register useless
for real :-)
It is still possible to provide an explicit __gtype_name__ member in the
subclass as it allows having a predictible GType name, which is handy
for some of our tests. There is also an explicit special case for
overrides because we obviously do not want to register new GTypes for
those ones as it would clearly defeat the purpose of overrides.
https://bugzilla.gnome.org/show_bug.cgi?id=543056
gobject/__init__.py | 6 +++---
tests/test_gi.py | 21 ++-------------------
2 files changed, 5 insertions(+), 22 deletions(-)
---
diff --git a/gobject/__init__.py b/gobject/__init__.py
index 31e6bb0..1858d18 100644
--- a/gobject/__init__.py
+++ b/gobject/__init__.py
@@ -106,9 +106,9 @@ class GObjectMeta(type):
if '__gtype__' in namespace:
return
- if not ('__gproperties__' in namespace or
- '__gsignals__' in namespace or
- '__gtype_name__' in namespace):
+ # Do not register a new GType for the overrides, as this would sort of
+ # defeat the purpose of overrides...
+ if cls.__module__.startswith('gi.overrides.'):
return
type_register(cls, namespace.get('__gtype_name__'))
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 3121a68..a218ec0 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -1365,8 +1365,6 @@ class TestGObject(unittest.TestCase):
class TestPythonGObject(unittest.TestCase):
class Object(GIMarshallingTests.Object):
- __gtype_name__ = "Object"
-
def __init__(self, int):
GIMarshallingTests.Object.__init__(self)
self.val = None
@@ -1386,8 +1384,6 @@ class TestPythonGObject(unittest.TestCase):
self.props.int += int8
class SubObject(GIMarshallingTests.SubObject):
- __gtype_name__ = "SubObject"
-
def __init__(self, int):
GIMarshallingTests.SubObject.__init__(self)
self.val = None
@@ -1414,8 +1410,6 @@ class TestPythonGObject(unittest.TestCase):
self.assertEqual(object_.props.int, 84)
class ObjectWithoutVFunc(GIMarshallingTests.Object):
- __gtype_name__ = 'ObjectWithoutVFunc'
-
def __init__(self, int):
GIMarshallingTests.Object.__init__(self)
@@ -1457,7 +1451,6 @@ class TestInterfaces(unittest.TestCase):
def test_implementation(self):
class TestInterfaceImpl(GObject.GObject, GIMarshallingTests.Interface):
- __gtype_name__ = 'TestInterfaceImpl'
def __init__(self):
GObject.GObject.__init__(self)
self.val = None
@@ -1474,24 +1467,15 @@ class TestInterfaces(unittest.TestCase):
self.assertEquals(instance.val, 42)
class TestInterfaceImplA(TestInterfaceImpl):
- __gtype_name__ = 'TestInterfaceImplA'
+ pass
class TestInterfaceImplB(TestInterfaceImplA):
- __gtype_name__ = 'TestInterfaceImplB'
+ pass
instance = TestInterfaceImplA()
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)
# -- this needs some additions to GIMarshallingTests in gobject-introspection
#class TestInterfaceClash(unittest.TestCase):
@@ -1499,7 +1483,6 @@ class TestInterfaces(unittest.TestCase):
# def test_clash(self):
# def create_clash():
# class TestClash(GObject.GObject, GIMarshallingTests.Interface, GIMarshallingTests.Interface2):
-# __gtype_name__ = 'TestClash'
# def do_test_int8_in(self, int8):
# pass
# TestClash()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]