[pygi] Return an empty list when a NULL GList and GSList is returned
- From: Tomeu Vizoso <tomeuv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygi] Return an empty list when a NULL GList and GSList is returned
- Date: Sat, 22 May 2010 11:22:09 +0000 (UTC)
commit 4b369f8aca980fc6a582094d6648f40fe4af5e9f
Author: John (J5) Palmieri <johnp redhat com>
Date: Sat May 22 13:21:30 2010 +0200
Return an empty list when a NULL GList and GSList is returned
* In GTK a GList * and GSList set to NULL is equivilant to empty list. All
GTK list methods can take a NULL and treat it as an empty list. e.g.
g_list_length(NULL) returns 0
* PyGtk consitently returns empty list when a NULL is returned for GList or
GSList return
* Many PyGtk apps do this:
for i in range(len(obj.get_list())):
...
* If we were to continue to return None, they would have to add a check
which is needlessly verbose and isn't very "pythonic"
https://bugzilla.gnome.org/show_bug.cgi?id=619232
gi/pygi-argument.c | 6 ------
tests/test_everything.py | 4 ++--
2 files changed, 2 insertions(+), 8 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 930df31..6461980 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -1563,12 +1563,6 @@ _pygi_argument_to_object (GArgument *arg,
GITransfer item_transfer;
gsize i;
- if (arg->v_pointer == NULL) {
- object = Py_None;
- Py_INCREF(object);
- break;
- }
-
list = arg->v_pointer;
length = g_slist_length(list);
diff --git a/tests/test_everything.py b/tests/test_everything.py
index ab4bdc9..5953dd1 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -65,8 +65,8 @@ class TestNullableArgs(unittest.TestCase):
self.assertEqual(None, Everything.test_ghash_null_out())
def test_out_nullable_list(self):
- self.assertEqual(None, Everything.test_gslist_null_out())
- self.assertEqual(None, Everything.test_glist_null_out())
+ self.assertEqual([], Everything.test_gslist_null_out())
+ self.assertEqual([], Everything.test_glist_null_out())
def test_out_nullable_array(self):
self.assertEqual(None, Everything.test_array_int_null_out())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]