From aa238dc73a2633fe4c0fb95ff50a4f0ac4a4af00 Mon Sep 17 00:00:00 2001 From: Siddharth Velankar Date: Mon, 24 Jul 2017 21:49:15 -0400 Subject: [PATCH] bpo-30732: json.dumps() lacks information about RecursionError related to default function --- Modules/_json.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Modules/_json.c b/Modules/_json.c index 6cc31c6e371224..f960867cc3beed 100644 --- a/Modules/_json.c +++ b/Modules/_json.c @@ -1502,7 +1502,16 @@ encoder_listencode_obj(PyEncoderObject *s, _PyAccu *acc, return -1; } } + newobj = PyObject_CallFunctionObjArgs(s->defaultfn, obj, NULL); + + if (obj != NULL && newobj != NULL && newobj->ob_type == obj->ob_type) { + PyErr_SetString(PyExc_TypeError, "Default serialization function returning same type"); + Py_DECREF(newobj); + Py_XDECREF(ident); + return -1; + } + if (newobj == NULL) { Py_XDECREF(ident); return -1;