From a67c70d4a945e9fc5f37165d1c61e6955e0dc8c8 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Thu, 23 Sep 2010 20:16:03 +0000 Subject: [PATCH] Merged revisions 84984 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r84984 | mark.dickinson | 2010-09-23 21:11:19 +0100 (Thu, 23 Sep 2010) | 5 lines 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. ........ --- Lib/test/test_descr.py | 5 +++++ Misc/NEWS | 4 ++++ Objects/typeobject.c | 4 ---- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 82dcc2c3d0..320a7a70f6 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -289,6 +289,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... diff --git a/Misc/NEWS b/Misc/NEWS index d46f6b1899..723c47bfed 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,10 @@ What's New in Python 3.1.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 #9804: ascii() now always represents unicode surrogate pairs as a single ``\UXXXXXXXX``, regardless of whether the character is printable or not. Also, the "backslashreplace" error handler now joins surrogate diff --git a/Objects/typeobject.c b/Objects/typeobject.c index d2124f17c3..ab942c0b97 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -4049,10 +4049,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); } -- 2.40.0