]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #9930: Remove an unnecessary type check in wrap_binaryfunc_r;
authorMark Dickinson <dickinsm@gmail.com>
Thu, 23 Sep 2010 20:11:19 +0000 (20:11 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Thu, 23 Sep 2010 20:11:19 +0000 (20:11 +0000)
this was causing reversed method calls like float.__radd__(3.0, 1) to
return NotImplemented instead of the expected numeric value.

Lib/test/test_descr.py
Misc/NEWS
Objects/typeobject.c

index 09798802f3a32061a43ad2867748ad44b5df2667..47fecfe34fa99bbbcb7953590d8fe94df4137938 100644 (file)
@@ -285,6 +285,11 @@ class OperatorsTest(unittest.TestCase):
         self.assertEqual(repr(a), "234.5")
         self.assertEqual(a.prec, 12)
 
+    def test_explicit_reverse_methods(self):
+        # see issue 9930
+        self.assertEqual(complex.__radd__(3j, 4.0), complex(4.0, 3.0))
+        self.assertEqual(float.__rsub__(3.0, 1), -2.0)
+
     @support.impl_detail("the module 'xxsubtype' is internal")
     def test_spam_lists(self):
         # Testing spamlist operations...
index 9480cf447bc6cb9b89d45b2b54722ba982c319bb..c353810e61b0199d47993b88ef87656fc4a0a06a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@ What's New in Python 3.2 Alpha 3?
 Core and Builtins
 -----------------
 
+- Issue #9930: Remove bogus subtype check that was causing (e.g.)
+  float.__rdiv__(2.0, 3) to return NotImplemented instead of the
+  expected 1.5.
+
 - Issue #9808: Implement os.getlogin for Windows. Patch by Jon Anglin.
 
 - Issue #9901: Destroying the GIL in Py_Finalize() can fail if some other
index 897374d48794eb48fb153ed5bca26de351e34f7d..7bdcb1233cf8567843a4e019a3ed481527f4e7c4 100644 (file)
@@ -4063,10 +4063,6 @@ wrap_binaryfunc_r(PyObject *self, PyObject *args, void *wrapped)
     if (!check_num_args(args, 1))
         return NULL;
     other = PyTuple_GET_ITEM(args, 0);
-    if (!PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
     return (*func)(other, self);
 }