By default, != returns the opposite of ==, unless the latter returns

NotImplemented.

(Is this worth backporting to 2.6?  It seems so useful...!)
This commit is contained in:
Guido van Rossum 2007-03-27 22:37:34 +00:00
parent a4335b1e6b
commit e27dc72308
3 changed files with 25 additions and 1 deletions

View file

@ -39,6 +39,12 @@ class ComparisonTest(unittest.TestCase):
self.assertEqual(a == b, id(a) == id(b),
'a=%r, b=%r' % (a, b))
def test_ne_defaults_to_not_eq(self):
a = Cmp(1)
b = Cmp(1)
self.assertTrue(a == b)
self.assertFalse(a != b)
def test_main():
test_support.run_unittest(ComparisonTest)