File tree 1 file changed +18
-4
lines changed
1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 38
38
of the same class, thus must follow the same rules)
39
39
"""
40
40
41
+ import sys
41
42
import re
42
43
43
44
@@ -211,14 +212,27 @@ def __repr__(self):
211
212
return "LooseVersion ('%s')" % str (self )
212
213
213
214
def _cmp (self , other ):
214
- if isinstance (other , str ):
215
- other = LooseVersion (other )
216
- elif not isinstance (other , LooseVersion ):
217
- return NotImplemented
215
+ other = self ._coerce (other )
218
216
219
217
if self .version == other .version :
220
218
return 0
221
219
if self .version < other .version :
222
220
return - 1
223
221
if self .version > other .version :
224
222
return 1
223
+
224
+ @staticmethod
225
+ def _coerce (other ):
226
+ if isinstance (other , LooseVersion ):
227
+ return other
228
+ elif isinstance (other , str ):
229
+ return LooseVersion (other )
230
+ elif "distutils" in sys .modules :
231
+ # Using this check to avoid importing distutils and suppressing the warning
232
+ try :
233
+ from distutils .version import LooseVersion as deprecated
234
+ except ImportError :
235
+ return NotImplemented
236
+ if isinstance (other , deprecated ):
237
+ return LooseVersion (str (other ))
238
+ return NotImplemented
You can’t perform that action at this time.
0 commit comments