diff -r adcd9131b7c6 Lib/test/test_sys.py --- a/Lib/test/test_sys.py Fri Dec 09 00:41:46 2016 +0100 +++ b/Lib/test/test_sys.py Mon Jan 02 10:27:17 2017 +0530 @@ -21,6 +21,7 @@ except ImportError: threading = None + class SysModuleTest(unittest.TestCase): def setUp(self): @@ -833,6 +834,25 @@ self.assertIsInstance(level, int) self.assertGreater(level, 0) + def test_sys_tracebacklimit(self): + p = subprocess.Popen([sys.executable, "-c", '1/0'], + stderr=subprocess.PIPE) + out = p.communicate()[1].strip() + traceback = b' File "", line 1, in ' + self.assertTrue(traceback in out) + + sys.tracebacklimit = 0 + code = textwrap.dedent(""" + import sys + + sys.tracebacklimit = 0 + + 1 / 0""") + p = subprocess.Popen([sys.executable, "-c", code], + stderr=subprocess.PIPE) + out = p.communicate()[1].strip() + self.assertFalse(traceback in out) + @test.support.cpython_only class SizeofTest(unittest.TestCase): diff -r adcd9131b7c6 Python/traceback.c --- a/Python/traceback.c Fri Dec 09 00:41:46 2016 +0100 +++ b/Python/traceback.c Mon Jan 02 10:27:17 2017 +0530 @@ -1,4 +1,3 @@ - /* Traceback implementation */ #include "Python.h" @@ -489,7 +488,7 @@ PyErr_Fetch(&exc_type, &exc_value, &exc_tb); limit = PyLong_AsLong(limitv); - if (limit == -1 && PyErr_Occurred()) { + if (PyErr_Occurred()) { if (PyErr_ExceptionMatches(PyExc_OverflowError)) { limit = PyTraceBack_LIMIT; } @@ -500,9 +499,6 @@ return 0; } } - else if (limit <= 0) { - limit = PyTraceBack_LIMIT; - } PyErr_Restore(exc_type, exc_value, exc_tb); } err = PyFile_WriteString("Traceback (most recent call last):\n", f); @@ -820,4 +816,3 @@ return NULL; } -