[Python-checkins] r84984 - in python/branches/py3k: Lib/test/test_descr.py Misc/NEWS Objects/typeobject.c

mark.dickinson python-checkins at python.org
Thu Sep 23 22:11:19 CEST 2010


Author: mark.dickinson
Date: Thu Sep 23 22:11:19 2010
New Revision: 84984

Log:
Issue #9930: Remove an unnecessary type check in wrap_binaryfunc_r;
this was causing reversed method calls like float.__radd__(3.0, 1) to
return NotImplemented instead of the expected numeric value.



Modified:
   python/branches/py3k/Lib/test/test_descr.py
   python/branches/py3k/Misc/NEWS
   python/branches/py3k/Objects/typeobject.c

Modified: python/branches/py3k/Lib/test/test_descr.py
==============================================================================
--- python/branches/py3k/Lib/test/test_descr.py	(original)
+++ python/branches/py3k/Lib/test/test_descr.py	Thu Sep 23 22:11:19 2010
@@ -285,6 +285,11 @@
         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...

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Thu Sep 23 22:11:19 2010
@@ -10,6 +10,10 @@
 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

Modified: python/branches/py3k/Objects/typeobject.c
==============================================================================
--- python/branches/py3k/Objects/typeobject.c	(original)
+++ python/branches/py3k/Objects/typeobject.c	Thu Sep 23 22:11:19 2010
@@ -4063,10 +4063,6 @@
     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);
 }
 


More information about the Python-checkins mailing list