mirror of
https://github.com/python/cpython.git
synced 2025-11-26 13:22:51 +00:00
Issue #1717: Remove cmp. Stage 1: remove all uses of cmp and __cmp__ from
the standard library and tests.
This commit is contained in:
parent
191e850053
commit
a56c467ac3
32 changed files with 210 additions and 216 deletions
|
|
@ -439,13 +439,24 @@ class CommonTest(seq_tests.CommonTest):
|
|||
self.assertRaises(TypeError, u.sort, 42, 42)
|
||||
|
||||
def revcmp(a, b):
|
||||
return cmp(b, a)
|
||||
if a == b:
|
||||
return 0
|
||||
elif a < b:
|
||||
return 1
|
||||
else: # a > b
|
||||
return -1
|
||||
u.sort(key=CmpToKey(revcmp))
|
||||
self.assertEqual(u, self.type2test([2,1,0,-1,-2]))
|
||||
|
||||
# The following dumps core in unpatched Python 1.5:
|
||||
def myComparison(x,y):
|
||||
return cmp(x%3, y%7)
|
||||
xmod, ymod = x%3, y%7
|
||||
if xmod == ymod:
|
||||
return 0
|
||||
elif xmod < ymod:
|
||||
return -1
|
||||
else: # xmod > ymod
|
||||
return 1
|
||||
z = self.type2test(range(12))
|
||||
z.sort(key=CmpToKey(myComparison))
|
||||
|
||||
|
|
@ -453,7 +464,12 @@ class CommonTest(seq_tests.CommonTest):
|
|||
|
||||
def selfmodifyingComparison(x,y):
|
||||
z.append(1)
|
||||
return cmp(x, y)
|
||||
if x == y:
|
||||
return 0
|
||||
elif x < y:
|
||||
return -1
|
||||
else: # x > y
|
||||
return 1
|
||||
self.assertRaises(ValueError, z.sort, key=CmpToKey(selfmodifyingComparison))
|
||||
|
||||
self.assertRaises(TypeError, z.sort, 42, 42, 42, 42)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue