Skip to content

Commit ea82972

Browse files
committed
Issue python#14376: sys.exit now accepts longs as well as ints. Thanks Gareth Rees.
1 parent ebfb2f7 commit ea82972

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

Lib/test/test_sys.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,17 @@ def test_exit(self):
164164
self.assertEqual(out, b'')
165165
self.assertEqual(err, b'')
166166

167+
# test that the exit machinery handles long exit codes
168+
rc, out, err = assert_python_failure('-c', 'raise SystemExit(47L)')
169+
self.assertEqual(rc, 47)
170+
self.assertEqual(out, b'')
171+
self.assertEqual(err, b'')
172+
173+
rc, out, err = assert_python_ok('-c', 'raise SystemExit(0L)')
174+
self.assertEqual(rc, 0)
175+
self.assertEqual(out, b'')
176+
self.assertEqual(err, b'')
177+
167178
def check_exit_message(code, expected, **env_vars):
168179
rc, out, err = assert_python_failure('-c', code, **env_vars)
169180
self.assertEqual(rc, 1)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 2.7.14?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #14376: Allow sys.exit to accept longs as well as ints. Patch
14+
by Gareth Rees.
15+
1316
- Issue #29028: Fixed possible use-after-free bugs in the subscription of the
1417
buffer object with custom index object.
1518

Python/pythonrun.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ handle_system_exit(void)
11271127
/* If we failed to dig out the 'code' attribute,
11281128
just let the else clause below print the error. */
11291129
}
1130-
if (PyInt_Check(value))
1130+
if (PyInt_Check(value) || PyLong_Check(value))
11311131
exitcode = (int)PyInt_AsLong(value);
11321132
else {
11331133
PyObject *sys_stderr = PySys_GetObject("stderr");

0 commit comments

Comments
 (0)