From 794d8fe86cae14d0a82ce6abcd3666dbdfaf157e Mon Sep 17 00:00:00 2001 From: Duane Griffin Date: Sun, 25 May 2025 16:21:04 +1200 Subject: [PATCH] gh-134644: handle exceptions set in `PyOS_Readline` The builtin input calls `PyOS_Readline` but seems to assume it does not set exceptions: if the call fails it checks signals and runs handlers if any are pending, which will cause an assertion failure if an exception has already been set. Fix this by only checking signals if an exception has not already been set. --- Python/bltinmodule.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 3d0295ee3883f2..e88157a3c840d0 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -2426,7 +2426,8 @@ builtin_input_impl(PyObject *module, PyObject *prompt) } s = PyOS_Readline(stdin, stdout, promptstr); if (s == NULL) { - PyErr_CheckSignals(); + if (!PyErr_Occurred()) + PyErr_CheckSignals(); if (!PyErr_Occurred()) PyErr_SetNone(PyExc_KeyboardInterrupt); goto _readline_errors;