Author: guido.van.rossum
Date: Sun Jan  6 01:09:11 2008
New Revision: 59761

Modified:
   python/branches/py3k/Lib/test/test_compare.py
   python/branches/py3k/Misc/NEWS
   python/branches/py3k/Objects/typeobject.c
Log:
Issue #1393: object_richcompare() returns NotImplemented instead of
 False if the objects aren't equal, to give the other side a chance.


Modified: python/branches/py3k/Lib/test/test_compare.py
==============================================================================
--- python/branches/py3k/Lib/test/test_compare.py       (original)
+++ python/branches/py3k/Lib/test/test_compare.py       Sun Jan  6 01:09:11 2008
@@ -16,6 +16,13 @@
     def __eq__(self, other):
         return self.arg == other
 
+class Anything:
+    def __eq__(self, other):
+        return True
+
+    def __ne__(self, other):
+        return False
+
 class ComparisonTest(unittest.TestCase):
     set1 = [2, 2.0, 2, 2+0j, Cmp(2.0)]
     set2 = [[1], (3,), None, Empty()]
@@ -45,6 +52,15 @@
         self.assertTrue(a == b)
         self.assertFalse(a != b)
 
+    def test_issue_1393(self):
+        x = lambda: None
+        self.assertEqual(x, Anything())
+        self.assertEqual(Anything(), x)
+        y = object()
+        self.assertEqual(y, Anything())
+        self.assertEqual(Anything(), y)
+
+
 def test_main():
     test_support.run_unittest(ComparisonTest)
 

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS      (original)
+++ python/branches/py3k/Misc/NEWS      Sun Jan  6 01:09:11 2008
@@ -12,6 +12,9 @@
 Core and Builtins
 -----------------
 
+- Issue #1393: object_richcompare() returns NotImplemented instead of
+  False if the objects aren't equal, to give the other side a chance.
+
 - Issue #1692: Interpreter was not displaying location of SyntaxError
 
 - Improve some exception messages when Windows fails to load an extension

Modified: python/branches/py3k/Objects/typeobject.c
==============================================================================
--- python/branches/py3k/Objects/typeobject.c   (original)
+++ python/branches/py3k/Objects/typeobject.c   Sun Jan  6 01:09:11 2008
@@ -2484,7 +2484,10 @@
        switch (op) {
 
        case Py_EQ:
-               res = (self == other) ? Py_True : Py_False;
+               /* Return NotImplemented instead of False, so if two
+                  objects are compared, both get a chance at the
+                  comparison.  See issue #1393. */
+               res = (self == other) ? Py_True : Py_NotImplemented;
                Py_INCREF(res);
                break;
 
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to