[Python-checkins] cpython (2.7): Issue #14376: sys.exit now accepts longs as well as ints. Thanks Gareth Rees.
mark.dickinson
python-checkins at python.org
Thu Feb 2 14:32:10 EST 2017
https://hg.python.org/cpython/rev/14682d00b09a
changeset: 106394:14682d00b09a
branch: 2.7
parent: 106379:d7804789368a
user: Mark Dickinson <dickinsm at gmail.com>
date: Thu Feb 02 19:31:53 2017 +0000
summary:
Issue #14376: sys.exit now accepts longs as well as ints. Thanks Gareth Rees.
files:
Lib/test/test_sys.py | 11 +++++++++++
Misc/NEWS | 3 +++
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
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -164,6 +164,17 @@
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)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
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
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1127,7 +1127,7 @@
/* 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");
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list