[Piglit] [PATCH] registry/gl.py: remove redundant if trees

Dylan Baker baker.dylan.c at gmail.com
Wed Feb 18 17:06:44 PST 2015


Essentially this replace checks of
if thing_that_returns_bool:
        return True
return False

with:

return thing_that_returns_bool

And throws away about 15 lines of code in doing so.

I have verified that this produces the same output as before this patch
by running
diff -NaurBw <original output> <new output>

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---

I can't believe I didn't see what I was doing the first time
around...jeez.

 registry/gl.py | 30 +++++++-----------------------
 1 file changed, 7 insertions(+), 23 deletions(-)

diff --git a/registry/gl.py b/registry/gl.py
index 2f8cda0..075935a 100644
--- a/registry/gl.py
+++ b/registry/gl.py
@@ -562,16 +562,10 @@ class Extension(object):
             return False
         elif self.is_ratified != other.is_ratified:
             # sort ratified before unratified
-            if self.is_ratified:
-                return True
-            else:
-                return False
+            return self.is_ratified
         elif (other.vendor_namespace == 'EXT') != (self.vendor_namespace == 'EXT'):
             # Sort EXT before others
-            if self.vendor_namespace == 'EXT':
-                return True
-            else:
-                return False
+            return self.vendor_namespace == 'EXT'
         return self.name < other.name
 
     def __repr__(self):
@@ -1152,35 +1146,25 @@ class Enum(object):
 
         """
         if self.num_value != other.num_value:
-            if self.num_value < other.num_value:
-                return True
-            return False
+            return self.num_value < other.num_value
 
         x = self.vendor_namespace is None
         y = other.vendor_namespace is None
         if x != y:
-            if x and not y:
-                return True
-            return False
+            return x and not y
 
         x = self.vendor_namespace in Extension.RATIFIED_NAMESPACES
         y = other.vendor_namespace in Extension.RATIFIED_NAMESPACES
         if x != y:
-            if x and not y:
-                return True
-            return False
+            return x and not y
 
         x = self.vendor_namespace == 'EXT'
         y = other.vendor_namespace == 'EXT'
         if x != y:
-            if x and not y:
-                return True
-            return False
+            return x and not y
 
         if self.name != other.name:
-            if self.name < other.name:
-                return True
-            return False
+            return self.name < other.name
 
         return self.api < other.api
 
-- 
2.3.0



More information about the Piglit mailing list