Skip to content

gh-134644: handle exceptions set in PyOS_Readline #134645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Python/bltinmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Comment on lines +2429 to 2432
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like if clauses that have the same condition right next to each other. Let's refactor to something like this:

Suggested change
if (!PyErr_Occurred())
PyErr_CheckSignals();
if (!PyErr_Occurred())
PyErr_SetNone(PyExc_KeyboardInterrupt);
if (!PyErr_Occurred()) {
if (PyErr_CheckSignals() == 0) {
PyErr_SetNone(PyExc_KeyboardInterrupt);
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it looks a little goofy. I'm happy to take your version, but looking at it again, what about:

if (!PyErr_Occurred() && !PyErr_CheckSignals()) {
    PyErr_SetNone(PyExc_KeyboardInterrupt);
}

goto _readline_errors;
Expand Down
Loading