[pygobject] pygi-property: Lookup property in base classes of non-introspected types
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] pygi-property: Lookup property in base classes of non-introspected types
- Date: Mon, 24 Sep 2012 07:51:40 +0000 (UTC)
commit 4bfe7972546413f46f5c36737ff03bb5612c1921
Author: Olivier CrÃte <olivier crete collabora com>
Date: Tue Sep 18 08:52:02 2012 +0200
pygi-property: Lookup property in base classes of non-introspected types
Look for introspection data in the base classes of non-introspected gtypes.
This is necessary to look up introspection data for plugins.
https://bugzilla.gnome.org/show_bug.cgi?id=684058
gi/pygi-property.c | 28 ++++++++++++++--------------
tests/test_everything.py | 12 ++++++++++++
2 files changed, 26 insertions(+), 14 deletions(-)
---
diff --git a/gi/pygi-property.c b/gi/pygi-property.c
index 7c83eef..14564d0 100644
--- a/gi/pygi-property.c
+++ b/gi/pygi-property.c
@@ -54,27 +54,27 @@ _pygi_lookup_property_from_g_type (GType g_type, const gchar *attr_name)
repository = g_irepository_get_default();
info = g_irepository_find_by_gtype (repository, g_type);
- if (info == NULL) {
- return NULL;
- }
+ if (info != NULL) {
- n_infos = g_object_info_get_n_properties ( (GIObjectInfo *) info);
- for (i = 0; i < n_infos; i++) {
- GIPropertyInfo *property_info;
+ n_infos = g_object_info_get_n_properties ( (GIObjectInfo *) info);
+ for (i = 0; i < n_infos; i++) {
+ GIPropertyInfo *property_info;
- property_info = g_object_info_get_property ( (GIObjectInfo *) info, i);
- g_assert (info != NULL);
+ property_info = g_object_info_get_property ( (GIObjectInfo *) info,
+ i);
+ g_assert (info != NULL);
- if (strcmp (attr_name, g_base_info_get_name (property_info)) == 0) {
- g_base_info_unref (info);
- return property_info;
+ if (strcmp (attr_name, g_base_info_get_name (property_info)) == 0) {
+ g_base_info_unref (info);
+ return property_info;
+ }
+
+ g_base_info_unref (property_info);
}
- g_base_info_unref (property_info);
+ g_base_info_unref (info);
}
- g_base_info_unref (info);
-
parent = g_type_parent (g_type);
if (parent > 0)
return _pygi_lookup_property_from_g_type (parent, attr_name);
diff --git a/tests/test_everything.py b/tests/test_everything.py
index 243e770..b45f444 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -596,6 +596,18 @@ class TestProperties(unittest.TestCase):
object_.props.gtype = str
self.assertEqual(object_.props.gtype, GObject.TYPE_STRING)
+ def test_parent_class(self):
+ class A(Everything.TestObj):
+ prop1 = GObject.Property(type=int)
+
+ a = A()
+ a.props.int = 20
+ self.assertEqual(a.props.int, 20)
+
+ # test parent property which needs introspection
+ a.props.list = ("str1", "str2")
+ self.assertEqual(a.props.list, ["str1", "str2"])
+
class TestTortureProfile(unittest.TestCase):
def test_torture_profile(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]