From ec77866fbe58f6e2d84ec21780ed8ac67f2d1faf Mon Sep 17 00:00:00 2001 From: Arnold Dumas Date: Sun, 14 Jul 2019 11:29:55 +0200 Subject: [PATCH 1/4] bpo-24053: Add EXIT_SUCCESS and EXIT_FAILURE values in the sys module --- Doc/library/sys.rst | 20 +++++++++++++++++++ Lib/test/test_sys.py | 11 ++++++++++ .../2019-07-14-12-40-19.bpo-24053.jVpLIJ.rst | 1 + Python/sysmodule.c | 3 +++ 4 files changed, 35 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2019-07-14-12-40-19.bpo-24053.jVpLIJ.rst diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 4b0bcde4a8b495..751322d951dce3 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1613,6 +1613,26 @@ always available. .. versionadded:: 3.2 +.. data:: EXIT_SUCCESS + + An int you can use to indicate your program ended gracefully. + + .. code-block:: python + + sys.exit(sys.EXIT_SUCCESS) + + .. versionadded:: 3.10 + +.. data:: EXIT_FAILURE + + An int you can use to indicate your program encountered an error. + + .. code-block:: python + + sys.exit(sys.EXIT_FAILURE) + + .. versionadded:: 3.10 + .. rubric:: Citations .. [C99] ISO/IEC 9899:1999. "Programming languages -- C." A public draft of this standard is available at http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf\ . diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 947c935f34728a..ec14807c9ceec3 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -154,6 +154,17 @@ def test_exit(self): self.assertEqual(out, b'') self.assertEqual(err, b'') + # test EXIT_SUCCESS and EXIT_FAILURE constants + self.assertNotEqual(sys.EXIT_SUCCESS, sys.EXIT_FAILURE) + rc, out, err = assert_python_ok('-c', 'import sys; sys.exit(sys.EXIT_SUCCESS)') + self.assertEqual(rc, sys.EXIT_SUCCESS) + self.assertEqual(out, b'') + self.assertEqual(err, b'') + rc, out, err = assert_python_failure('-c', 'import sys; sys.exit(sys.EXIT_FAILURE)') + self.assertEqual(rc, sys.EXIT_FAILURE) + self.assertEqual(out, b'') + self.assertEqual(err, b'') + def check_exit_message(code, expected, **env_vars): rc, out, err = assert_python_failure('-c', code, **env_vars) self.assertEqual(rc, 1) diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-07-14-12-40-19.bpo-24053.jVpLIJ.rst b/Misc/NEWS.d/next/Core and Builtins/2019-07-14-12-40-19.bpo-24053.jVpLIJ.rst new file mode 100644 index 00000000000000..3dd3e44d721078 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2019-07-14-12-40-19.bpo-24053.jVpLIJ.rst @@ -0,0 +1 @@ +Add EXIT_FAILURE and EXIT_SUCCESS in the sys module. diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 30c7e987461b2a..0031f055c13f3e 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2959,6 +2959,9 @@ _PySys_Create(PyThreadState *tstate, PyObject **sysmod_p) return _PyStatus_ERR("failed to create a module object"); } + PyModule_AddIntMacro(sysmod, EXIT_SUCCESS); + PyModule_AddIntMacro(sysmod, EXIT_FAILURE); + PyObject *sysdict = PyModule_GetDict(sysmod); if (sysdict == NULL) { return _PyStatus_ERR("can't initialize sys dict"); From 372b7b7c319e80a177b9e685e3cf5a90434f9cbc Mon Sep 17 00:00:00 2001 From: Ethan Furman Date: Tue, 6 Oct 2026 09:30:43 -0700 Subject: [PATCH 2/4] Apply batched suggestions from code review Co-authored-by: Ethan Furman --- Doc/library/sys.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 751322d951dce3..f641c9752619a2 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1621,7 +1621,7 @@ always available. sys.exit(sys.EXIT_SUCCESS) - .. versionadded:: 3.10 + .. versionadded:: 3.16 .. data:: EXIT_FAILURE @@ -1631,7 +1631,7 @@ always available. sys.exit(sys.EXIT_FAILURE) - .. versionadded:: 3.10 + .. versionadded:: 3.16 .. rubric:: Citations From f495ffffd4649359dbd97f1573e3b25fba2473c2 Mon Sep 17 00:00:00 2001 From: Ethan Furman Date: Mon, 12 Oct 2026 11:52:19 -0700 Subject: [PATCH 3/4] Delete Misc/NEWS.d/next/Core and Builtins/2019-07-14-12-40-19.bpo-24053.jVpLIJ.rst --- .../Core and Builtins/2019-07-14-12-40-19.bpo-24053.jVpLIJ.rst | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Misc/NEWS.d/next/Core and Builtins/2019-07-14-12-40-19.bpo-24053.jVpLIJ.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-07-14-12-40-19.bpo-24053.jVpLIJ.rst b/Misc/NEWS.d/next/Core and Builtins/2019-07-14-12-40-19.bpo-24053.jVpLIJ.rst deleted file mode 100644 index 3dd3e44d721078..00000000000000 --- a/Misc/NEWS.d/next/Core and Builtins/2019-07-14-12-40-19.bpo-24053.jVpLIJ.rst +++ /dev/null @@ -1 +0,0 @@ -Add EXIT_FAILURE and EXIT_SUCCESS in the sys module. From c1c695869dd9aae06660b8f1203bb07916cddd39 Mon Sep 17 00:00:00 2001 From: Ethan Furman Date: Mon, 12 Oct 2026 11:59:41 -0700 Subject: [PATCH 4/4] add news file --- .../2026-10-12-11-59-37.gh-issue-68241.jVpLIJ.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-10-12-11-59-37.gh-issue-68241.jVpLIJ.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-10-12-11-59-37.gh-issue-68241.jVpLIJ.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-12-11-59-37.gh-issue-68241.jVpLIJ.rst new file mode 100644 index 00000000000000..3dd3e44d721078 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-12-11-59-37.gh-issue-68241.jVpLIJ.rst @@ -0,0 +1 @@ +Add EXIT_FAILURE and EXIT_SUCCESS in the sys module.