Index: Lib/test/test_set.py =================================================================== --- Lib/test/test_set.py (revision 66902) +++ Lib/test/test_set.py (working copy) @@ -202,9 +202,6 @@ s = self.thetype(t) self.assertEqual(len(s), 3) - def test_compare(self): - self.assertRaises(TypeError, self.s.__cmp__, self.s) - def test_sub_and_super(self): p, q, r = map(self.thetype, ['ab', 'abcde', 'def']) self.assert_(p < q) Index: Lib/test/test_descr.py =================================================================== --- Lib/test/test_descr.py (revision 66902) +++ Lib/test/test_descr.py (working copy) @@ -1566,7 +1566,7 @@ for i in range(10): self.assert_(i in d1) self.assertFalse(10 in d1) - # Test overridden behavior for static classes + # Test overridden behavior class Proxy(object): def __init__(self, x): self.x = x @@ -1578,8 +1578,14 @@ return self.x == other def __ne__(self, other): return self.x != other - def __cmp__(self, other): - return cmp(self.x, other.x) + def __ge__(self, other): + return self.x >= other + def __gt__(self, other): + return self.x > other + def __le__(self, other): + return self.x <= other + def __lt__(self, other): + return self.x < other def __str__(self): return "Proxy:%s" % self.x def __repr__(self): @@ -1596,9 +1602,10 @@ self.assertNotEqual(p0, p1) self.assert_(not p0 != p0) self.assertEqual(not p0, p1) - self.assertEqual(cmp(p0, p1), -1) - self.assertEqual(cmp(p0, p0), 0) - self.assertEqual(cmp(p0, p_1), 1) + self.assert_(p0 < p1) + self.assert_(p0 <= p1) + self.assert_(p1 > p0) + self.assert_(p1 >= p0) self.assertEqual(str(p0), "Proxy:0") self.assertEqual(repr(p0), "Proxy(0)") p10 = Proxy(range(10)) @@ -1606,46 +1613,6 @@ for i in range(10): self.assert_(i in p10) self.assertFalse(10 in p10) - # Test overridden behavior for dynamic classes - class DProxy(object): - def __init__(self, x): - self.x = x - def __bool__(self): - return not not self.x - def __hash__(self): - return hash(self.x) - def __eq__(self, other): - return self.x == other - def __ne__(self, other): - return self.x != other - def __cmp__(self, other): - return cmp(self.x, other.x) - def __str__(self): - return "DProxy:%s" % self.x - def __repr__(self): - return "DProxy(%r)" % self.x - def __contains__(self, value): - return value in self.x - p0 = DProxy(0) - p1 = DProxy(1) - p_1 = DProxy(-1) - self.assertFalse(p0) - self.assert_(not not p1) - self.assertEqual(hash(p0), hash(0)) - self.assertEqual(p0, p0) - self.assertNotEqual(p0, p1) - self.assertNotEqual(not p0, p0) - self.assertEqual(not p0, p1) - self.assertEqual(cmp(p0, p1), -1) - self.assertEqual(cmp(p0, p0), 0) - self.assertEqual(cmp(p0, p_1), 1) - self.assertEqual(str(p0), "DProxy:0") - self.assertEqual(repr(p0), "DProxy(0)") - p10 = DProxy(range(10)) - self.assertFalse(-1 in p10) - for i in range(10): - self.assert_(i in p10) - self.assertFalse(10 in p10) ## # Safety test for __cmp__ ## def unsafecmp(a, b): Index: Lib/test/test_long.py =================================================================== --- Lib/test/test_long.py (revision 66902) +++ Lib/test/test_long.py (working copy) @@ -669,10 +669,22 @@ else: raise TypeError("can't deal with %r" % val) - def __cmp__(self, other): + def _cmp__(self, other): if not isinstance(other, Rat): other = Rat(other) return cmp(self.n * other.d, self.d * other.n) + def __eq__(self, other): + return self._cmp__(other) == 0 + def __ne__(self, other): + return self._cmp__(other) != 0 + def __ge__(self, other): + return self._cmp__(other) >= 0 + def __gt__(self, other): + return self._cmp__(other) > 0 + def __le__(self, other): + return self._cmp__(other) <= 0 + def __lt__(self, other): + return self._cmp__(other) < 0 cases = [0, 0.001, 0.99, 1.0, 1.5, 1e20, 1e200] # 2**48 is an important boundary in the internals. 2**53 is an Index: Lib/test/test_hash.py =================================================================== --- Lib/test/test_hash.py (revision 66902) +++ Lib/test/test_hash.py (working copy) @@ -78,7 +78,6 @@ ] error_expected = [NoHash(), OnlyEquality(), - OnlyCmp(), ] def test_default_hash(self): Index: Lib/test/test_richcmp.py =================================================================== --- Lib/test/test_richcmp.py (revision 66902) +++ Lib/test/test_richcmp.py (working copy) @@ -198,13 +198,11 @@ def __le__(self, other): raise TestFailed("This shouldn't happen") def __ge__(self, other): raise TestFailed("This shouldn't happen") def __ne__(self, other): raise TestFailed("This shouldn't happen") - def __cmp__(self, other): raise RuntimeError("expected") a = Misb() b = Misb() self.assertEqual(ab, 0) - self.assertRaises(RuntimeError, cmp, a, b) def test_not(self): # Check that exceptions in __bool__ are properly Index: Lib/test/test_class.py =================================================================== --- Lib/test/test_class.py (revision 66902) +++ Lib/test/test_class.py (working copy) @@ -92,10 +92,6 @@ return 1.0 @trackCall -def __cmp__(self, *args): - return 0 - -@trackCall def __eq__(self, *args): return True @@ -465,11 +461,6 @@ hash(C0()) # This should work; the next two should raise TypeError - class C1: - def __cmp__(self, other): return 0 - - self.assertRaises(TypeError, hash, C1()) - class C2: def __eq__(self, other): return 1