[gobject-introspection] giscanner: Update namespace sort for Python 3 compatibility
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] giscanner: Update namespace sort for Python 3 compatibility
- Date: Wed, 30 Sep 2015 03:35:40 +0000 (UTC)
commit c6aba9366a31eda73c6f3f07893bf9603374782d
Author: Simon Feltman <sfeltman src gnome org>
Date: Mon Apr 28 20:38:18 2014 -0700
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
giscanner/transformer.py | 17 ++++++++++-------
1 files changed, 10 insertions(+), 7 deletions(-)
---
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index 968db75..d1fddaf 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)]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]