[py] only set RuntimeError string when needed in gen_code.py (closes gh-303) fix/pyexceptions master
authorPaul Brossier <piem@piem.org>
Fri, 10 Apr 2026 15:11:58 +0000 (12:11 -0300)
committerPaul Brossier <piem@piem.org>
Fri, 10 Apr 2026 15:11:58 +0000 (12:11 -0300)
python/lib/gen_code.py

index 95b9fa5..fbb06a0 100644 (file)
@@ -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__)