From: Xavier Fernandez Date: Tue, 21 Mar 2017 15:23:09 +0000 (+0100) Subject: Simplify Message.__cmp__ X-Git-Tag: v2.5.0~11^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=57d47e0d69217c2fa5aec3a072a4972823669db3;p=thirdparty%2Fbabel.git Simplify Message.__cmp__ --- diff --git a/babel/messages/catalog.py b/babel/messages/catalog.py index 018094ca..193b72bc 100644 --- a/babel/messages/catalog.py +++ b/babel/messages/catalog.py @@ -116,21 +116,13 @@ class Message(object): return '<%s %r (flags: %r)>' % (type(self).__name__, self.id, list(self.flags)) - def __cmp__(self, obj): + def __cmp__(self, other): """Compare Messages, taking into account plural ids""" - def values_to_compare(): - if isinstance(obj, Message): - plural = self.pluralizable - obj_plural = obj.pluralizable - if plural and obj_plural: - return self.id[0], obj.id[0] - elif plural: - return self.id[0], obj.id - elif obj_plural: - return self.id, obj.id[0] - return self.id, obj.id - this, other = values_to_compare() - return cmp(this, other) + def values_to_compare(obj): + if isinstance(obj, Message) and obj.pluralizable: + return obj.id[0] + return obj.id + return cmp(values_to_compare(self), values_to_compare(other)) def __gt__(self, other): return self.__cmp__(other) > 0