https://github.com/python/cpython/commit/25b17d4d5171f5d72b90aca6ecefcce24730b018
commit: 25b17d4d5171f5d72b90aca6ecefcce24730b018
branch: main
author: Arnold Dumas <[email protected]>
committer: ethanfurman <[email protected]>
date: 2026-10-20T10:10:10-07:00
summary:

bpo-24053: Add EXIT_SUCCESS and EXIT_FAILURE values in the sys module (GH-14773)

Co-authored-by: Ethan Furman <[email protected]>

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2026-10-12-11-59-37.gh-issue-68241.jVpLIJ.rst
M Doc/library/sys.rst
M Lib/test/test_sys.py
M Python/sysmodule.c

diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst
index d1b23dfc52b2b9..aa13a9225d6748 100644
--- a/Doc/library/sys.rst
+++ b/Doc/library/sys.rst
@@ -2432,6 +2432,26 @@ always available. Unless explicitly noted otherwise, all 
variables are read-only
    .. 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.16
+
+.. 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.16
+
 .. rubric:: Citations
 
 .. [C99] ISO/IEC 9899:1999.  "Programming languages -- C."  A public draft of 
this standard is available at 
https://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 af99437821d2c3..c6056154e2d037 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -265,6 +265,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/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.
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index a284c8322eac70..ce75027f67e9f4 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -4380,6 +4380,9 @@ _PySys_Create(PyThreadState *tstate, PyObject **sysmod_p)
     PyUnstable_Module_SetGIL(sysmod, Py_MOD_GIL_NOT_USED);
 #endif
 
+    PyModule_AddIntMacro(sysmod, EXIT_SUCCESS);
+    PyModule_AddIntMacro(sysmod, EXIT_FAILURE);
+
     PyObject *sysdict = PyModule_GetDict(sysmod);
     if (sysdict == NULL) {
         goto error;

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to