After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 619232 - [PATCH] When converting lists to python objects, convert NULL to empty list
[PATCH] When converting lists to python objects, convert NULL to empty list
Status: RESOLVED FIXED
Product: pygi
Classification: Deprecated
Component: general
unspecified
Other Linux
: Normal normal
: 0.6
Assigned To: pygi-maint
pygi-maint
Depends on:
Blocks:
 
 
Reported: 2010-05-20 20:39 UTC by johnp
Modified: 2010-05-22 11:22 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
[PATCH] Return an empty list when a NULL GList and GSList is returned (1.21 KB, patch)
2010-05-20 20:39 UTC, johnp
committed Details | Review

Description johnp 2010-05-20 20:39:17 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.
Comment 1 johnp 2010-05-20 20:39:43 UTC
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(-)
Comment 2 Tomeu Vizoso 2010-05-22 11:20:11 UTC
Review of attachment 161586 [details] [review]:

Love these patches that fix stuff by removing code.