Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.15.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ Other language changes
* Several error messages incorrectly using the term "argument" have been corrected.
(Contributed by Stan Ulbrych in :gh:`133382`.)

* :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.
(Contributed by Bénédikt Tran in :gh:`133548`.)


New modules
Expand Down
3 changes: 2 additions & 1 deletion Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,8 @@ sys_exit_impl(PyObject *module, PyObject *status)
{
/* Raise SystemExit so callers may catch it or clean up. */
if (PyTuple_Check(status)) {
/* Make sure that tuples are not flattened during normalization. */
/* Make sure that tuples are not flattened during normalization
* due to the fast path for tuples in _PyErr_CreateException(). */
Copy link
Member

Choose a reason for hiding this comment

The 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 _PyErr_CreateException has a bug or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it was designed as such for conveniency. It was added in 3a84097 but AFAICT, that was just refactoring of c0dc92a (1997) which already had this fast path.

PyObject *exc = PyObject_CallOneArg(PyExc_SystemExit, status);
PyErr_SetObject(PyExc_SystemExit, exc);
Py_DECREF(exc);
Expand Down
Loading