From f66505b9e43226d731fefdfd37325f411f7e0de1 Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Mon, 27 Aug 2007 15:59:00 +0000 Subject: Refactor a bit to make sure that it is possible to use in subclasses, 2007-08-27 Johan Dahlin * gobject/__init__.py (GObjectMeta._install_properties): Refactor a bit to make sure that it is possible to use in subclasses, fixes #470718 (Marco Giusti) svn path=/trunk/; revision=699 --- ChangeLog | 6 ++++++ gobject/__init__.py | 15 +++++++-------- tests/test_properties.py | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index ca14101..2a80343 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-08-27 Johan Dahlin + + * gobject/__init__.py (GObjectMeta._install_properties): + Refactor a bit to make sure that it is possible to use in subclasses, + fixes #470718 (Marco Giusti) + 2007-08-27 Marco Giusti reviewed by: Gustavo J. A. M. Carneiro diff --git a/gobject/__init__.py b/gobject/__init__.py index d251d31..c1404f9 100644 --- a/gobject/__init__.py +++ b/gobject/__init__.py @@ -42,27 +42,26 @@ class GObjectMeta(type): def _install_properties(cls): gproperties = getattr(cls, '__gproperties__', {}) - props = {} + + props = [] for name, prop in cls.__dict__.items(): if isinstance(prop, property): # not same as the built-in if name in gproperties: raise ValueError prop.name = name - props[name] = prop.get_pspec_args() + gproperties[name] = prop.get_pspec_args() + props.append(prop) if not props: return - if not gproperties: - cls.__gproperties__ = props - else: - gproperties.update(props) + cls.__gproperties__ = gproperties if (hasattr(cls, 'do_get_property') or hasattr(cls, 'do_set_property')): for prop in props: - if (prop.getter != prop.default_getter or - prop.setter != prop.default_setter): + if (prop.getter != prop._default_getter or + prop.setter != prop._default_setter): raise TypeError( "GObject subclass %r defines do_get/set_property" " and it also uses a property which a custom setter" diff --git a/tests/test_properties.py b/tests/test_properties.py index 2b9e1a1..de93f62 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -313,6 +313,20 @@ class TestProperty(unittest.TestCase): pobj1 = pobj2.obj self.assertEqual(hash(pobj1), obj1_hash) + def testPropertySubclass(self): + # test for #470718 + class A(GObject): + prop1 = gobject.property(type=int) + + class B(A): + prop2 = gobject.property(type=int) + + b = B() + b.prop2 = 10 + self.assertEquals(b.prop2, 10) + b.prop1 = 20 + self.assertEquals(b.prop1, 20) + if __name__ == '__main__': unittest.main() -- cgit