diff --git a/traceback2/__init__.py b/traceback2/__init__.py index 562d2a8..7b5f503 100644 --- a/traceback2/__init__.py +++ b/traceback2/__init__.py @@ -530,7 +530,7 @@ class TracebackException: lineno = str(self.lineno) or u('?') yield u(' File "{0}", line {1}\n').format(filename, lineno) - badline = u(self.text) + badline = self.text and u(self.text) offset = self.offset if badline is not None: yield u(' {0}\n').format(badline.strip()) diff --git a/traceback2/tests/test_traceback.py b/traceback2/tests/test_traceback.py index 40652bd..afc4a4a 100644 --- a/traceback2/tests/test_traceback.py +++ b/traceback2/tests/test_traceback.py @@ -779,3 +779,16 @@ class TestTracebackException(unittest.TestCase): exc = traceback.TracebackException(Exception, e, tb) self.assertEqual(exc.stack[0].locals, None) + def test_syntax_no_extras(self): + linecache.updatecache('/foo.py', fake_module) + e = SyntaxError("uh oh") + c = test_code('/foo.py', 'method') + f = test_frame(c, fake_module, {'something': 1}) + tb = test_tb(f, 6, None) + exc = traceback.TracebackException(SyntaxError, e, tb) + self.assertEqual([ + u('Traceback (most recent call last):\n'), + u(' File "/foo.py", line 6, in method\n from io import StringIO\n'), + u(' File "", line None\n'), + u('SyntaxError: uh oh\n')], + list(exc.format()))