diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2017-02-02 19:31:53 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2017-02-02 19:31:53 (GMT) |
commit | ea82972ec887cf7b92e0a8c14074bf9dc04d0f50 (patch) | |
tree | 4a58e7591275ec7957d40d81a1734ae0d76c08ad | |
parent | ebfb2f76c5c7e1f5e3a37b719501e0e1ae6f680f (diff) | |
download | cpython-ea82972ec887cf7b92e0a8c14074bf9dc04d0f50.zip cpython-ea82972ec887cf7b92e0a8c14074bf9dc04d0f50.tar.gz cpython-ea82972ec887cf7b92e0a8c14074bf9dc04d0f50.tar.bz2 |
Issue #14376: sys.exit now accepts longs as well as ints. Thanks Gareth Rees.
-rw-r--r-- | Lib/test/test_sys.py | 11 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Python/pythonrun.c | 2 |
3 files changed, 15 insertions, 1 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 95bd26e..5baaa35 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -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) @@ -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. diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 7b85268..2ffecc7 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -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"); |