From acf99ce7f84980be17550cb590c2eb3dadf358e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Thu, 12 Nov 2026 22:00:11 +0000 Subject: [PATCH] Chain multiple pending exceptions for Python 3 --- PythonClientUser.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/PythonClientUser.cpp b/PythonClientUser.cpp index 9facd95..eafdc62 100644 --- a/PythonClientUser.cpp +++ b/PythonClientUser.cpp @@ -111,6 +111,16 @@ void PythonClientUser::Reset() void PythonClientUser::SetPendingException(PyObject *type, PyObject *value, PyObject *tb) { +#if PY_MAJOR_VERSION >= 3 + if (pendingExcValue) + { + PyErr_NormalizeException(&pendingExcType, &pendingExcValue, &pendingExcTb); + PyErr_NormalizeException(&type, &value, &tb); + Py_INCREF(pendingExcValue); + PyException_SetContext(value, pendingExcValue); + } +#endif + // Clear any existing pending exception first Py_XDECREF(pendingExcType); Py_XDECREF(pendingExcValue);