python: Fix rich comparisons
authorMathieu Bridon <bochecha@daitauha.fr>
Tue, 17 Jul 2018 20:57:39 +0000 (22:57 +0200)
committerDylan Baker <dylan@pnwbakers.com>
Tue, 7 Aug 2018 20:10:34 +0000 (13:10 -0700)
Python 3 doesn't call objects __cmp__() methods any more to compare
them. Instead, it requires implementing the rich comparison methods
explicitly: __eq__(), __ne(), __lt__(), __le__(), __gt__() and __ge__().

Fortunately Python 2 also supports those.

This commit only implements the comparison methods which are actually
used by the build scripts.

Signed-off-by: Mathieu Bridon <bochecha@daitauha.fr>
Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
src/amd/vulkan/radv_extensions.py
src/intel/vulkan/anv_extensions.py
src/mapi/mapi_abi.py

index 15d29becfd45118f483a73d99378d48204177583..8b5eee867ac20fcfe04880532abe3cd4e9e9d2be 100644 (file)
@@ -147,14 +147,15 @@ class VkVersion:
         patch = self.patch if self.patch is not None else 0
         return (self.major << 22) | (self.minor << 12) | patch
 
-    def __cmp__(self, other):
+    def __gt__(self, other):
         # If only one of them has a patch version, "ignore" it by making
         # other's patch version match self.
         if (self.patch is None) != (other.patch is None):
             other = copy.copy(other)
             other.patch = self.patch
 
-        return self.__int_ver().__cmp__(other.__int_ver())
+        return self.__int_ver() > other.__int_ver()
+
 
 MAX_API_VERSION = VkVersion(MAX_API_VERSION)
 
index cffc3e700cb0ccb7fa8f2a8ce6958dbd677c062e..9a65aed1c467800a1b7d1c384f1c5c19c1481acf 100644 (file)
@@ -160,14 +160,15 @@ class VkVersion:
         patch = self.patch if self.patch is not None else 0
         return (self.major << 22) | (self.minor << 12) | patch
 
-    def __cmp__(self, other):
+    def __gt__(self, other):
         # If only one of them has a patch version, "ignore" it by making
         # other's patch version match self.
         if (self.patch is None) != (other.patch is None):
             other = copy.copy(other)
             other.patch = self.patch
 
-        return self.__int_ver().__cmp__(other.__int_ver())
+        return self.__int_ver() > other.__int_ver()
+
 
 
 MAX_API_VERSION = VkVersion('0.0.0')
index be1d15d9224e1592abc76dab736ac56e1dcfb982..e4ce2b6cafde0845c24c97e63e6b60bda40dbf91 100644 (file)
@@ -121,19 +121,18 @@ class ABIEntry(object):
     def __str__(self):
         return self.c_prototype()
 
-    def __cmp__(self, other):
+    def __lt__(self, other):
         # compare slot, alias, and then name
-        res = cmp(self.slot, other.slot)
-        if not res:
+        if self.slot == other.slot:
             if not self.alias:
-                res = -1
+                return True
             elif not other.alias:
-                res = 1
+                return False
 
-            if not res:
-                res = cmp(self.name, other.name)
+            return self.name < other.name
+
+        return self.slot < other.slot
 
-        return res
 
 def abi_parse_xml(xml):
     """Parse a GLAPI XML file for ABI entries."""