Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b09a3d6

Browse files
committed
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.
1 parent e8e4b3b commit b09a3d6

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

Lib/test/test_descr.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ def __repr__(self):
285285
self.assertEqual(repr(a), "234.5")
286286
self.assertEqual(a.prec, 12)
287287

288+
def test_explicit_reverse_methods(self):
289+
# see issue 9930
290+
self.assertEqual(complex.__radd__(3j, 4.0), complex(4.0, 3.0))
291+
self.assertEqual(float.__rsub__(3.0, 1), -2.0)
292+
288293
@support.impl_detail("the module 'xxsubtype' is internal")
289294
def test_spam_lists(self):
290295
# Testing spamlist operations...

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ What's New in Python 3.2 Alpha 3?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #9930: Remove bogus subtype check that was causing (e.g.)
14+
float.__rdiv__(2.0, 3) to return NotImplemented instead of the
15+
expected 1.5.
16+
1317
- Issue #9808: Implement os.getlogin for Windows. Patch by Jon Anglin.
1418

1519
- Issue #9901: Destroying the GIL in Py_Finalize() can fail if some other

Objects/typeobject.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4063,10 +4063,6 @@ wrap_binaryfunc_r(PyObject *self, PyObject *args, void *wrapped)
40634063
if (!check_num_args(args, 1))
40644064
return NULL;
40654065
other = PyTuple_GET_ITEM(args, 0);
4066-
if (!PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) {
4067-
Py_INCREF(Py_NotImplemented);
4068-
return Py_NotImplemented;
4069-
}
40704066
return (*func)(other, self);
40714067
}
40724068

0 commit comments

Comments
 (0)