From ad5cf975aed08cc4562dd008cf9f83b12b82ffb8 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Fri, 10 Apr 2026 12:11:58 -0300 Subject: [PATCH] [py] only set RuntimeError string when needed in gen_code.py (closes gh-303) --- python/lib/gen_code.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/lib/gen_code.py b/python/lib/gen_code.py index 95b9fa54..fbb06a03 100644 --- a/python/lib/gen_code.py +++ b/python/lib/gen_code.py @@ -345,7 +345,8 @@ Py_{shortname}_init (Py_{shortname} * self, PyObject * args, PyObject * kwds) out += """ // return -1 and set error string on failure if (self->o == NULL) {{ - PyErr_Format (PyExc_RuntimeError, "failed creating {shortname}"); + if (PyErr_Occurred() == NULL) + PyErr_Format (PyExc_RuntimeError, "failed creating {shortname}"); return -1; }} """.format(paramchars = paramchars, paramvals = paramvals, **self.__dict__) -- 2.11.0