summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Dahlin <jdahlin@async.com.br>2007-08-27 15:59:00 +0000
committerJohan Dahlin <johan@src.gnome.org>2007-08-27 15:59:00 +0000
commitf66505b9e43226d731fefdfd37325f411f7e0de1 (patch)
treedaccdf37ef74de09a53323503f8100fa960ec285
parent078439f05b12ed4756e87f0e8c1c6ff1e93da880 (diff)
downloadpygobject-f66505b9e43226d731fefdfd37325f411f7e0de1.tar.gz
Refactor a bit to make sure that it is possible to use in subclasses,
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) svn path=/trunk/; revision=699
-rw-r--r--ChangeLog6
-rw-r--r--gobject/__init__.py15
-rw-r--r--tests/test_properties.py14
3 files changed, 27 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index ca14101c..2a803431 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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 d251d31c..c1404f91 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 2b9e1a1d..de93f624 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()