Commit 076ba315 authored by Simon van der Linden's avatar Simon van der Linden
Browse files

Fix members initialization in metaclasses

In metaclasses, the test for the name of the class was wrong, since it
prevented one to create a subclass with the same name (especially annoying for
overrides). Now, if a GType is available from the info, the fact that it
doesn't have any wrapper yet means that the metaclass is creating the base
class, which will be registerd just after its creation. This is true for
objects, and for structures registered as boxed or pointer too.

This patch includes a test for basic subclassing in Python. It notably tests
that methods don't get overridden by the metaclass.
parent ac80e64c
......@@ -116,7 +116,7 @@ class GObjectMeta(gobject.GObjectMeta, MetaClassHelper):
super(GObjectMeta, cls).__init__(name, bases, dict_)
# Avoid touching anything else than the base class.
if cls.__name__ != cls.__info__.get_name():
if cls.__info__.get_g_type().pytype is not None:
return;
cls._setup_methods()
......@@ -157,7 +157,8 @@ class StructMeta(type, MetaClassHelper):
super(StructMeta, cls).__init__(name, bases, dict_)
# Avoid touching anything else than the base class.
if cls.__name__ != cls.__info__.get_name():
g_type = cls.__info__.get_g_type()
if g_type != gobject.TYPE_INVALID and g_type.pytype is not None:
return;
cls._setup_fields()
......
......@@ -1422,6 +1422,25 @@ class TestGObject(unittest.TestCase):
# self.assertEquals(object_.__grefcount__, 1)
class TestPythonGObject(unittest.TestCase):
class Object(TestGI.Object):
__gtype_name__ = "Object"
def method(self):
# Don't call super, which asserts that self.int == 42.
pass
def test_object(self):
self.assertTrue(issubclass(self.Object, TestGI.Object))
object_ = self.Object(int = 42)
self.assertTrue(isinstance(object_, self.Object))
def test_object_method(self):
self.Object(int = 0).method()
class TestMultiOutputArgs(unittest.TestCase):
def test_int_out_out(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment