summaryrefslogtreecommitdiff
path: root/giscanner/transformer.py
diff options
context:
space:
mode:
authorSimon Feltman <sfeltman@src.gnome.org>2014-04-28 20:38:18 -0700
committerColin Walters <walters@verbum.org>2015-09-29 23:16:32 -0400
commitc6aba9366a31eda73c6f3f07893bf9603374782d (patch)
treed1d28af0748fb7eedd6ee757c361274d1c376906 /giscanner/transformer.py
parent4ab4f3b0467616904ad5c114ea55325610d55087 (diff)
downloadgobject-introspection-c6aba9366a31eda73c6f3f07893bf9603374782d.tar.gz
giscanner: Update namespace sort for Python 3 compatibility
Use key function instead of cmp for list.sort which is compatible with both Python 2 and 3. Make sure a list is returned from split function. Don't use identity comparison "is" on strings. https://bugzilla.gnome.org/show_bug.cgi?id=679438
Diffstat (limited to 'giscanner/transformer.py')
-rw-r--r--giscanner/transformer.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index 968db755..d1fddaf1 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -244,12 +244,15 @@ currently-scanned namespace is first."""
for ns in self._parsed_includes.values():
yield ns
- def _sort_matches(self, x, y):
- if x[0] is self._namespace:
- return 1
- elif y[0] is self._namespace:
- return -1
- return cmp(x[2], y[2])
+ def _sort_matches(self, val):
+ """Key sort which ensures items in self._namespace are last by returning
+ a tuple key starting with 1 for self._namespace entries and 0 for
+ everythin else.
+ """
+ if val[0] == self._namespace:
+ return 1, val[2]
+ else:
+ return 0, val[2]
def _split_c_string_for_namespace_matches(self, name, is_identifier=False):
if not is_identifier and self._symbol_filter_cmd:
@@ -283,7 +286,7 @@ currently-scanned namespace is first."""
else:
unprefixed_namespaces.append(ns)
if matches:
- matches.sort(self._sort_matches)
+ matches.sort(key=self._sort_matches)
return list(map(lambda x: (x[0], x[1]), matches))
elif self._accept_unprefixed:
return [(self._namespace, name)]