]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Simplify Message.__cmp__
authorXavier Fernandez <xavier.fernandez@polyconseil.fr>
Tue, 21 Mar 2017 15:23:09 +0000 (16:23 +0100)
committerXavier Fernandez <xavier.fernandez@polyconseil.fr>
Tue, 21 Mar 2017 15:23:09 +0000 (16:23 +0100)
babel/messages/catalog.py

index 018094ca4d4157d0cc395a475ece145b548749a7..193b72bcd3e87ac64eb35d545d731f09a949da6f 100644 (file)
@@ -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