GNOME Bugzilla – Bug 619232
[PATCH] When converting lists to python objects, convert NULL to empty list
Last modified: 2010-05-22 11:22:25 UTC
Returning None for an empty list is a pita because developers who expect an iterable object now have to special case for None when using API that returns a list. It is an unnecessary C'ism.
Created attachment 161586 [details] [review] [PATCH] 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" --- gi/pygi-argument.c | 6 ------ tests/test_everything.py | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-)
Review of attachment 161586 [details] [review]: Love these patches that fix stuff by removing code.