utils: Fix an instability in cmp method.

Signed-off-by: Tim 'mithro' Ansell <me@mith.ro>
This commit is contained in:
Tim 'mithro' Ansell 2019-01-30 15:29:58 +11:00
parent 522ac7901c
commit 2950a63769
1 changed files with 10 additions and 1 deletions

View File

@ -106,8 +106,17 @@ def cmp(a, b):
>>> cmp(b'AA', b'A')
1
>>> def bit(*args):
... return args
>>> a = ('CLBLL', 'L', 'SLICEL', ('X', 0), 'AFFMUX', 'XOR')
>>> b = ('CLBLL', 'L', 'SLICEL', ('X', 0), 'AFFMUX', ('F', 7))
>>> cmp(a, b)
-1
>>> cmp(b, a)
1
"""
if not isinstance(a, (str, bytes)):
if not isinstance(a, (str, bytes)) and not isinstance(b, (str, bytes)):
try:
for i, j in itertools.zip_longest(iter(a), iter(b)):
r = cmp(i, j)