Index: Python/errors.c =================================================================== --- Python/errors.c (revision 47106) +++ Python/errors.c (working copy) @@ -132,6 +132,7 @@ PyObject *value = *val; PyObject *inclass = NULL; PyObject *initial_tb = NULL; + PyThreadState *tstate = NULL; if (type == NULL) { /* There was no exception, so nothing to do. */ @@ -149,10 +150,12 @@ if (PyExceptionInstance_Check(value)) inclass = PyExceptionInstance_Class(value); + tstate = PyThreadState_GET(); + /* Normalize the exception so that if the type is a class, the value will be an instance. */ - if (PyExceptionClass_Check(type)) { + if (PyExceptionClass_Check(type) && (tstate->recursion_depth > 0)) { /* if the value was not an instance, or is not an instance whose class is (or is derived from) type, then use the value as an argument to instantiation of the type @@ -207,7 +210,9 @@ Py_DECREF(initial_tb); } /* normalize recursively */ + --tstate->recursion_depth; PyErr_NormalizeException(exc, val, tb); + ++tstate->recursion_depth; } Index: Objects/abstract.c =================================================================== --- Objects/abstract.c (revision 47106) +++ Objects/abstract.c (working copy) @@ -1796,7 +1796,11 @@ ternaryfunc call; if ((call = func->ob_type->tp_call) != NULL) { - PyObject *result = (*call)(func, arg, kw); + PyObject *result; + if (Py_EnterRecursiveCall(" while calling a Python object")) + return NULL; + result = (*call)(func, arg, kw); + Py_LeaveRecursiveCall(); if (result == NULL && !PyErr_Occurred()) PyErr_SetString( PyExc_SystemError, Index: Objects/typeobject.c =================================================================== --- Objects/typeobject.c (revision 47106) +++ Objects/typeobject.c (working copy) @@ -4591,16 +4591,7 @@ if (meth == NULL) return NULL; - /* PyObject_Call() will end up calling slot_tp_call() again if - the object returned for __call__ has __call__ itself defined - upon it. This can be an infinite recursion if you set - __call__ in a class to an instance of it. */ - if (Py_EnterRecursiveCall(" in __call__")) { - Py_DECREF(meth); - return NULL; - } res = PyObject_Call(meth, args, kwds); - Py_LeaveRecursiveCall(); Py_DECREF(meth); return res;