-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-133548: fix handling of empty and 1-item tuples for sys.exit
#135789
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
:func:`sys.exit` and :exc:`SystemExit` now correctly handle empty and 1-item | ||
tuples arguments. Previously, such tuples were unpacked by :func:`!sys.exit` | ||
but not by :exc:`!SystemExit` and the process status code was incorrectly | ||
set. Patch by Bénédikt Tran. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -916,7 +916,16 @@ sys_exit_impl(PyObject *module, PyObject *status) | |
/*[clinic end generated code: output=13870986c1ab2ec0 input=b86ca9497baa94f2]*/ | ||
{ | ||
/* Raise SystemExit so callers may catch it or clean up. */ | ||
PyErr_SetObject(PyExc_SystemExit, status); | ||
if (PyTuple_Check(status)) { | ||
/* Make sure that tuples are not flattened during normalization | ||
* due to the fast path for tuples in _PyErr_CreateException(). */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not a "fast path" if removing it changes behaviour. We need to understand whether There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
PyObject *exc = PyObject_CallOneArg(PyExc_SystemExit, status); | ||
PyErr_SetObject(PyExc_SystemExit, exc); | ||
Py_DECREF(exc); | ||
} | ||
else { | ||
PyErr_SetObject(PyExc_SystemExit, status); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this a problem with how There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's a bit unfortunate because that's how static PyObject*
_PyErr_CreateException(PyObject *exception_type, PyObject *value)
{
PyObject *exc;
if (value == NULL || value == Py_None) {
exc = _PyObject_CallNoArgs(exception_type);
}
else if (PyTuple_Check(value)) {
exc = PyObject_Call(exception_type, value, NULL);
}
else {
exc = PyObject_CallOneArg(exception_type, value);
}
if (exc != NULL && !PyExceptionInstance_Check(exc)) {
PyErr_Format(PyExc_TypeError,
"calling %R should have returned an instance of "
"BaseException, not %s",
exception_type, Py_TYPE(exc)->tp_name);
Py_CLEAR(exc);
}
return exc;
} Unless you want me to change |
||
return NULL; | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.