summaryrefslogtreecommitdiff
path: root/giscanner/girwriter.py
diff options
context:
space:
mode:
authorSimon Feltman <sfeltman@src.gnome.org>2014-04-30 17:08:29 -0700
committerColin Walters <walters@verbum.org>2015-09-29 23:16:32 -0400
commit10175a1b54fff30291bbb5ff849dc3a048a4b8dc (patch)
treee1e58f59728a2abac60e579cea3c929bd46b2ea8 /giscanner/girwriter.py
parent3dca44e3f1aba172b8a71d3860d55167dc35a5dc (diff)
downloadgobject-introspection-10175a1b54fff30291bbb5ff849dc3a048a4b8dc.tar.gz
giscanner: Use rich comparison methods for Python 3 compatibility
Add lt, le, gt, ge, eq, ne, and hash dunder methods to all classes that implement custom comparisons with __cmp__. This is needed to support Python 3 compatible sorting of instances of these classes. Avoid using @functools.total_ordering which does not work for some of these classes and also is not available in Python 2.6. https://bugzilla.gnome.org/show_bug.cgi?id=679438
Diffstat (limited to 'giscanner/girwriter.py')
-rw-r--r--giscanner/girwriter.py15
1 files changed, 5 insertions, 10 deletions
diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py
index 0df87ed4..e73dcaca 100644
--- a/giscanner/girwriter.py
+++ b/giscanner/girwriter.py
@@ -82,17 +82,12 @@ class GIRWriter(XMLWriter):
# We define a custom sorting function here because
# we want aliases to be first. They're a bit
# special because the typelib compiler expands them.
- def nscmp(a, b):
- if isinstance(a, ast.Alias):
- if isinstance(b, ast.Alias):
- return cmp(a.name, b.name)
- else:
- return -1
- elif isinstance(b, ast.Alias):
- return 1
+ def nscmp(val):
+ if isinstance(val, ast.Alias):
+ return 0, val
else:
- return cmp(a, b)
- for node in sorted(namespace.values(), cmp=nscmp):
+ return 1, val
+ for node in sorted(namespace.values(), key=nscmp):
self._write_node(node)
def _write_node(self, node):