Skip to content

Commit 854780a

Browse files
committed
Extract method for comparing prerelease. Satisfies complexity check.
1 parent 7c006d8 commit 854780a

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

distutils/version.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def __str__(self):
178178

179179
return vstring
180180

181-
def _cmp(self, other): # noqa: C901
181+
def _cmp(self, other):
182182
if isinstance(other, str):
183183
with suppress_known_deprecation():
184184
other = StrictVersion(other)
@@ -193,25 +193,28 @@ def _cmp(self, other): # noqa: C901
193193
else:
194194
return 1
195195

196-
# have to compare prerelease
197-
# case 1: neither has prerelease; they're equal
198-
# case 2: self has prerelease, other doesn't; other is greater
199-
# case 3: self doesn't have prerelease, other does: self is greater
200-
# case 4: both have prerelease: must compare them!
196+
return self._cmp_prerelease(other)
201197

198+
def _cmp_prerelease(self, other):
199+
"""
200+
case 1: neither has prerelease; they're equal
201+
case 2: self has prerelease, other doesn't; other is greater
202+
case 3: self doesn't have prerelease, other does: self is greater
203+
case 4: both have prerelease: must compare them!
204+
"""
202205
if not self.prerelease and not other.prerelease:
203206
return 0
204207
elif self.prerelease and not other.prerelease:
205208
return -1
206209
elif not self.prerelease and other.prerelease:
207210
return 1
208-
elif self.prerelease and other.prerelease:
209-
if self.prerelease == other.prerelease:
210-
return 0
211-
elif self.prerelease < other.prerelease:
212-
return -1
213-
else:
214-
return 1
211+
212+
if self.prerelease == other.prerelease:
213+
return 0
214+
elif self.prerelease < other.prerelease:
215+
return -1
216+
else:
217+
return 1
215218

216219

217220
# end class StrictVersion

0 commit comments

Comments
 (0)