summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Frécinaux <code@istique.net>2010-08-04 00:30:05 +0200
committerSteve Frécinaux <code@istique.net>2011-01-17 17:57:18 +0100
commit7cc8ac35bb0d8dbf7d66f014f8cd7ff070b3acb8 (patch)
tree87f1c784daa7ce42fa368217d7d5268e49bc0cb4
parent7a0548dbfbdfe481f75315b6bc7824a9f1a8a87b (diff)
downloadpygobject-7cc8ac35bb0d8dbf7d66f014f8cd7ff070b3acb8.tar.gz
Handle GObject subclasses in the property helper.
https://bugzilla.gnome.org/show_bug.cgi?id=625982
-rw-r--r--gobject/propertyhelper.py26
-rw-r--r--tests/test_properties.py9
2 files changed, 22 insertions, 13 deletions
diff --git a/gobject/propertyhelper.py b/gobject/propertyhelper.py
index 2f77a4d6..745a13c4 100644
--- a/gobject/propertyhelper.py
+++ b/gobject/propertyhelper.py
@@ -176,30 +176,30 @@ class property(object):
self._exc = None
raise exc
- def _type_from_python(self, type):
- if type == _long:
+ def _type_from_python(self, type_):
+ if type_ == _long:
return TYPE_LONG
- elif type == int:
+ elif type_ == int:
return TYPE_INT
- elif type == bool:
+ elif type_ == bool:
return TYPE_BOOLEAN
- elif type == float:
+ elif type_ == float:
return TYPE_DOUBLE
- elif type == str:
+ elif type_ == str:
return TYPE_STRING
- elif type == object:
+ elif type_ == object:
return TYPE_PYOBJECT
- elif type == _gobject.GObject:
- return TYPE_OBJECT
- elif type in [TYPE_NONE, TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR,
+ elif isinstance(type_, type) and issubclass(type_, _gobject.GObject):
+ return type_.__gtype__
+ elif type_ in [TYPE_NONE, TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR,
TYPE_INT, TYPE_UINT, TYPE_BOOLEAN, TYPE_LONG,
TYPE_ULONG, TYPE_INT64, TYPE_UINT64, TYPE_ENUM,
TYPE_FLAGS, TYPE_FLOAT, TYPE_DOUBLE, TYPE_POINTER,
TYPE_BOXED, TYPE_PARAM, TYPE_OBJECT, TYPE_STRING,
TYPE_PYOBJECT]:
- return type
+ return type_
else:
- raise TypeError("Unsupported type: %r" % (type,))
+ raise TypeError("Unsupported type: %r" % (type_,))
def _get_default(self, default):
ptype = self.type
@@ -296,7 +296,7 @@ class property(object):
args = (self.default,)
elif ptype == TYPE_PYOBJECT:
args = ()
- elif ptype == TYPE_OBJECT:
+ elif ptype.is_a(TYPE_OBJECT):
args = ()
else:
raise NotImplementedError(ptype)
diff --git a/tests/test_properties.py b/tests/test_properties.py
index d156199b..90db3ac6 100644
--- a/tests/test_properties.py
+++ b/tests/test_properties.py
@@ -336,6 +336,15 @@ class TestProperty(unittest.TestCase):
pobj1 = pobj2.obj
self.assertEqual(hash(pobj1), obj1_hash)
+ def testObjectSubclassProperty(self):
+ class ObjectSubclass(GObject):
+ __gtype_name__ = 'ObjectSubclass'
+
+ class PropertyObjectSubclass(GObject):
+ obj = gobject.property(type=ObjectSubclass)
+
+ obj1 = PropertyObjectSubclass(obj=ObjectSubclass())
+
def testPropertySubclass(self):
# test for #470718
class A(GObject):