summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Dahlin <johan@gnome.org>2008-03-21 18:06:56 +0000
committerJohan Dahlin <johan@src.gnome.org>2008-03-21 18:06:56 +0000
commit6ee167447336570b83e41ca2c4216d6e9058fd43 (patch)
tree4d444ea4a3626cc1a5e34f717828f4e133c451f9
parent56a637d7d8b19277f2eb947a250385fd6bba9a4e (diff)
downloadpygobject-6ee167447336570b83e41ca2c4216d6e9058fd43.tar.gz
pygobject-6ee167447336570b83e41ca2c4216d6e9058fd43.tar.xz
pygobject-6ee167447336570b83e41ca2c4216d6e9058fd43.zip
Allow gobject.property work with subclasses. Add tests.
2008-03-21 Johan Dahlin <johan@gnome.org> * gobject/__init__.py: * tests/test_properties.py: Allow gobject.property work with subclasses. Add tests. (#523352, Tomeu Vizoso) svn path=/trunk/; revision=752
-rw-r--r--ChangeLog8
-rw-r--r--gobject/__init__.py8
-rw-r--r--tests/test_properties.py35
3 files changed, 47 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index c91545c..eb5b290 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-03-21 Johan Dahlin <johan@gnome.org>
+
+ * gobject/__init__.py:
+ * tests/test_properties.py:
+ Allow gobject.property work with subclasses. Add tests.
+
+ (#523352, Tomeu Vizoso)
+
2008-03-10 Johan Dahlin <johan@gnome.org>
* configure.ac: Require gio and giounix 2.15.7.
diff --git a/gobject/__init__.py b/gobject/__init__.py
index c1404f9..488d87e 100644
--- a/gobject/__init__.py
+++ b/gobject/__init__.py
@@ -57,15 +57,16 @@ class GObjectMeta(type):
cls.__gproperties__ = gproperties
- if (hasattr(cls, 'do_get_property') or
- hasattr(cls, 'do_set_property')):
+ if ('do_get_property' in cls.__dict__ or
+ 'do_set_property' in cls.__dict__):
for prop in props:
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"
- " or getter. This is not allowed" % (cls,))
+ " or getter. This is not allowed" % (
+ cls.__name__,))
def obj_get_property(self, pspec):
name = pspec.name.replace('-', '_')
@@ -92,7 +93,6 @@ class GObjectMeta(type):
return
type_register(cls, namespace.get('__gtype_name__'))
-
_gobject._install_metaclass(GObjectMeta)
del _gobject
diff --git a/tests/test_properties.py b/tests/test_properties.py
index de93f62..a691b32 100644
--- a/tests/test_properties.py
+++ b/tests/test_properties.py
@@ -327,6 +327,41 @@ class TestProperty(unittest.TestCase):
b.prop1 = 20
self.assertEquals(b.prop1, 20)
+ def testPropertySubclassCustomSetter(self):
+ # test for #523352
+ class A(GObject):
+ def get_first(self):
+ return 'first'
+ first = gobject.property(type=str, getter=get_first)
+
+ class B(A):
+ def get_second(self):
+ return 'second'
+ second = gobject.property(type=str, getter=get_second)
+
+ a = A()
+ self.assertEquals(a.first, 'first')
+ self.assertRaises(TypeError, setattr, a, 'first', 'foo')
+
+ b = B()
+ self.assertEquals(b.first, 'first')
+ self.assertRaises(TypeError, setattr, b, 'first', 'foo')
+ self.assertEquals(b.second, 'second')
+ self.assertRaises(TypeError, setattr, b, 'second', 'foo')
+
+ def testPropertySubclassCustomSetterError(self):
+ try:
+ class A(GObject):
+ def get_first(self):
+ return 'first'
+ first = gobject.property(type=str, getter=get_first)
+
+ def do_get_property(self, pspec):
+ pass
+ except TypeError:
+ pass
+ else:
+ raise AssertionError
if __name__ == '__main__':
unittest.main()