[pygobject] Correctly set properties on object with statically defined properties
- From: Simon Feltman <sfeltman src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Correctly set properties on object with statically defined properties
- Date: Wed, 13 Feb 2013 08:31:33 +0000 (UTC)
commit 42cbff60e2032f715d9be6ab280954211899e03c
Author: Jonathan Ballet <jon multani info>
Date: Tue Feb 12 23:03:00 2013 +0100
Correctly set properties on object with statically defined properties
Fix failures in GObject.Object.set_properties() when used with
statically defined properties:
* Calling the method was raising a "SystemError: error return without
exception set" since `result` was (most of the time) still NULL at the
end of pygobject_set_properties()
* Calling the method with several properties would only set one of
the properties, since the function was exiting too early.
Signed-off-by: Simon Feltman <sfeltman src gnome org>
https://bugzilla.gnome.org/show_bug.cgi?id=693618
gi/_gobject/pygobject.c | 19 +++++++++++--------
tests/test_gi.py | 6 ++++++
2 files changed, 17 insertions(+), 8 deletions(-)
---
diff --git a/gi/_gobject/pygobject.c b/gi/_gobject/pygobject.c
index 045787b..8673e79 100644
--- a/gi/_gobject/pygobject.c
+++ b/gi/_gobject/pygobject.c
@@ -1453,14 +1453,17 @@ pygobject_set_properties(PyGObject *self, PyObject *args, PyObject *kwargs)
goto exit;
}
- ret = pygi_set_property_value (self, pspec, value);
- if (ret == 0)
- goto exit;
- else if (PyErr_Occurred())
- goto exit;
-
- if (!set_property_from_pspec(G_OBJECT(self->obj), pspec, value))
- goto exit;
+ ret = pygi_set_property_value (self, pspec, value);
+ if (ret != 0) {
+ /* Non-zero return code means that either an error occured ...*/
+ if (PyErr_Occurred())
+ goto exit;
+
+ /* ... or the property couldn't be found , so let's try the default
+ * call. */
+ if (!set_property_from_pspec(G_OBJECT(self->obj), pspec, value))
+ goto exit;
+ }
}
result = Py_None;
diff --git a/tests/test_gi.py b/tests/test_gi.py
index ee2f3de..4545539 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -2785,6 +2785,12 @@ class TestPropertiesObject(unittest.TestCase):
self.assertEqual(obj.props.some_variant.get_type_string(), 'b')
self.assertEqual(obj.props.some_variant.get_boolean(), True)
+ def test_setting_several_properties(self):
+ obj = GIMarshallingTests.PropertiesObject()
+ obj.set_properties(some_uchar=54, some_int=42)
+ self.assertEqual(42, obj.props.some_int)
+ self.assertEqual(54, obj.props.some_uchar)
+
class TestKeywords(unittest.TestCase):
def test_method(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]