diff --git a/Misc/NEWS b/Misc/NEWS index 93636941910..c63db58bddb 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -163,6 +163,10 @@ Build C API +- PyNumber_Coerce() and PyNumber_CoerceEx() now also invoke the type's + coercion if both arguments have the same type but this type has the + CHECKTYPES flag set. This is to better support proxies. + - The type of tp_free has been changed from "void (*)(PyObject *)" to "void (*)(void *)". diff --git a/Objects/object.c b/Objects/object.c index e47f80ea5b5..85fd35fc6b1 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -1427,7 +1427,10 @@ PyNumber_CoerceEx(PyObject **pv, PyObject **pw) register PyObject *w = *pw; int res; - if (v->ob_type == w->ob_type && !PyInstance_Check(v)) { + /* Shortcut only for old-style types */ + if (v->ob_type == w->ob_type && + !PyType_HasFeature(v->ob_type, Py_TPFLAGS_CHECKTYPES)) + { Py_INCREF(v); Py_INCREF(w); return 0;