diff --git a/Lib/test/test_pyrepl/test_pyrepl.py b/Lib/test/test_pyrepl/test_pyrepl.py index 1a76832386bf1d..3ee71fe330895b 100644 --- a/Lib/test/test_pyrepl/test_pyrepl.py +++ b/Lib/test/test_pyrepl/test_pyrepl.py @@ -1339,3 +1339,12 @@ def test_readline_history_file(self): def test_keyboard_interrupt_after_isearch(self): output, exit_code = self.run_repl(["\x12", "\x03", "exit"]) self.assertEqual(exit_code, 0) + + def test_exit_code(self): + _, exit_code = self.run_repl(["exit(128)"]) + self.assertEqual(exit_code, 128) + + env = os.environ.copy() + env["PYTHON_BASIC_REPL"] = "1" + _, exit_code = self.run_repl(["exit(64)"], env=env) + self.assertEqual(exit_code, 64) diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-10-23-19-57-22.gh-issue-125880.JSLK_q.rst b/Misc/NEWS.d/next/Core and Builtins/2024-10-23-19-57-22.gh-issue-125880.JSLK_q.rst new file mode 100644 index 00000000000000..6d5413f24aa5be --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-10-23-19-57-22.gh-issue-125880.JSLK_q.rst @@ -0,0 +1 @@ +Fix a bug in PyREPL that caused :func:`exit` to always return 1. diff --git a/Modules/main.c b/Modules/main.c index 15ea49a1bad19e..31fa0f40092524 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -100,8 +100,7 @@ pymain_err_print(int *exitcode_p) { int exitcode; if (_Py_HandleSystemExit(&exitcode)) { - *exitcode_p = exitcode; - return 1; + Py_Exit(exitcode); } PyErr_Print();