]> granicus.if.org Git - python/commitdiff
Issue #14376: sys.exit now accepts longs as well as ints. Thanks Gareth Rees.
authorMark Dickinson <dickinsm@gmail.com>
Thu, 2 Feb 2017 19:31:53 +0000 (19:31 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Thu, 2 Feb 2017 19:31:53 +0000 (19:31 +0000)
Lib/test/test_sys.py
Misc/NEWS
Python/pythonrun.c

index 95bd26e06fec17fbfad312dd26929998b3b65eb0..5baaa352c0ba76ba8045bb722de8e453604b1126 100644 (file)
@@ -164,6 +164,17 @@ class SysModuleTest(unittest.TestCase):
         self.assertEqual(out, b'')
         self.assertEqual(err, b'')
 
+        # test that the exit machinery handles long exit codes
+        rc, out, err = assert_python_failure('-c', 'raise SystemExit(47L)')
+        self.assertEqual(rc, 47)
+        self.assertEqual(out, b'')
+        self.assertEqual(err, b'')
+
+        rc, out, err = assert_python_ok('-c', 'raise SystemExit(0L)')
+        self.assertEqual(rc, 0)
+        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)
index 0e4921c09fa3712ccdebfea9656fc377d1f8f6a0..69033a3a999a1859bc4ce61c4cd94d9c742cccd9 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 2.7.14?
 Core and Builtins
 -----------------
 
+- Issue #14376: Allow sys.exit to accept longs as well as ints. Patch
+  by Gareth Rees.
+
 - Issue #29028: Fixed possible use-after-free bugs in the subscription of the
   buffer object with custom index object.
 
index 7b85268c632fccbf89598050d1bd5be6d1b64c32..2ffecc722dc317f91147d6f4f39bed5ff6e74225 100644 (file)
@@ -1127,7 +1127,7 @@ handle_system_exit(void)
         /* If we failed to dig out the 'code' attribute,
            just let the else clause below print the error. */
     }
-    if (PyInt_Check(value))
+    if (PyInt_Check(value) || PyLong_Check(value))
         exitcode = (int)PyInt_AsLong(value);
     else {
         PyObject *sys_stderr = PySys_GetObject("stderr");