diff options
author | Simon Feltman <sfeltman@src.gnome.org> | 2014-04-30 17:08:29 -0700 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2015-09-29 23:16:32 -0400 |
commit | 10175a1b54fff30291bbb5ff849dc3a048a4b8dc (patch) | |
tree | e1e58f59728a2abac60e579cea3c929bd46b2ea8 /giscanner/annotationparser.py | |
parent | 3dca44e3f1aba172b8a71d3860d55167dc35a5dc (diff) | |
download | gobject-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/annotationparser.py')
-rw-r--r-- | giscanner/annotationparser.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py index cd6fa4fa..d48ed616 100644 --- a/giscanner/annotationparser.py +++ b/giscanner/annotationparser.py @@ -114,6 +114,7 @@ from __future__ import unicode_literals import os import re +import operator from collections import namedtuple from operator import ne, gt, lt @@ -1054,11 +1055,32 @@ class GtkDocCommentBlock(GtkDocAnnotatable): #: applied to this :class:`GtkDocCommentBlock`. self.tags = OrderedDict() - def __cmp__(self, other): + def _compare(self, other, op): # Note: This is used by g-ir-annotation-tool, which does a ``sorted(blocks.values())``, # meaning that keeping this around makes update-glib-annotations.py patches # easier to review. - return cmp(self.name, other.name) + return op(self.name, other.name) + + def __lt__(self, other): + return self._compare(other, operator.lt) + + def __gt__(self, other): + return self._compare(other, operator.gt) + + def __ge__(self, other): + return self._compare(other, operator.ge) + + def __le__(self, other): + return self._compare(other, operator.le) + + def __eq__(self, other): + return self._compare(other, operator.eq) + + def __ne__(self, other): + return self._compare(other, operator.ne) + + def __hash__(self): + return hash(self.name) def __repr__(self): return "<GtkDocCommentBlock '%s' %r>" % (self.name, self.annotations) |