From 10175a1b54fff30291bbb5ff849dc3a048a4b8dc Mon Sep 17 00:00:00 2001 From: Simon Feltman Date: Wed, 30 Apr 2014 17:08:29 -0700 Subject: 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 --- giscanner/girwriter.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'giscanner/girwriter.py') 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): -- cgit v1.2.1