diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | gobject/__init__.py | 15 | ||||
-rw-r--r-- | tests/test_properties.py | 14 |
3 files changed, 27 insertions, 8 deletions
@@ -1,3 +1,9 @@ +2007-08-27 Johan Dahlin <jdahlin@async.com.br> + + * 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 <marco.giusti@gmail.com> 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() |