absurdfarce commented on code in PR #1273:
URL: 
https://github.com/apache/cassandra-python-driver/pull/1273#discussion_r2903367867


##########
cassandra/util.py:
##########
@@ -1757,48 +1746,32 @@ def __repr__(self):
     def __str__(self):
         return self._version
 
-    @staticmethod
-    def _compare_version_part(version, other_version, cmp):
-        if not (isinstance(version, int) and
-                isinstance(other_version, int)):
-            version = str(version)
-            other_version = str(other_version)
-
-        return cmp(version, other_version)
-
     def __eq__(self, other):
         if not isinstance(other, Version):
             return NotImplemented
 
         return (self.major == other.major and
                 self.minor == other.minor and
                 self.patch == other.patch and
-                self._compare_version_part(self.build, other.build, lambda s, 
o: s == o) and
-                self._compare_version_part(self.prerelease, other.prerelease, 
lambda s, o: s == o)
+                self.build == other.build and
+                self.prerelease == other.prerelease
                 )
 
     def __gt__(self, other):
         if not isinstance(other, Version):
             return NotImplemented
 
-        is_major_ge = self.major >= other.major
-        is_minor_ge = self.minor >= other.minor
-        is_patch_ge = self.patch >= other.patch
-        is_build_gt = self._compare_version_part(self.build, other.build, 
lambda s, o: s > o)
-        is_build_ge = self._compare_version_part(self.build, other.build, 
lambda s, o: s >= o)
-
-        # By definition, a prerelease comes BEFORE the actual release, so if a 
version
-        # doesn't have a prerelease, it's automatically greater than anything 
that does
-        if self.prerelease and not other.prerelease:
-            is_prerelease_gt = False
+        if self.major != other.major:
+            return self.major > other.major
+        elif self.minor != other.minor:
+            return self.minor > other.minor
+        elif self.patch != other.patch:
+            return self.patch > other.patch
+        elif self.build != other.build:
+            return self.build > other.build
+        elif self.prerelease and not other.prerelease:
+            return False

Review Comment:
   So after mulling this over for a few days @bschoening I think _I_ personally 
still like the if/else syntax more but I certainly don't feel strongly about it 
and I do like the fact that the tuple comparison is more concise.  I also 
concede the fact that your usage is probably more Pythonic.  I think I'd be 
quite happy with your syntax plus a short comment explaining why it works to 
folks who come across it and aren't familiar with how tuple comparisons work in 
Python.  I'll update this PR shortly with that change.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to