Unbreak handling of syntax errors with no line.
This was broken in the port back to 2.x.
This commit is contained in:
parent
9df5538af8
commit
70a91e4398
@ -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())
|
||||
|
@ -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 "<string>", line None\n'),
|
||||
u('SyntaxError: uh oh\n')],
|
||||
list(exc.format()))
|
||||
|
Loading…
x
Reference in New Issue
Block a user