diff --git a/IPython/core/tests/test_ultratb.py b/IPython/core/tests/test_ultratb.py index 49ca060..62e99ac 100644 --- a/IPython/core/tests/test_ultratb.py +++ b/IPython/core/tests/test_ultratb.py @@ -93,3 +93,9 @@ class IndentationErrorTest(unittest.TestCase): with tt.AssertPrints("IndentationError"): with tt.AssertPrints("zoon()", suppress=False): ip.magic('run %s' % fname) + +class SyntaxErrorTest(unittest.TestCase): + def test_syntaxerror_without_lineno(self): + with tt.AssertNotPrints("TypeError"): + with tt.AssertPrints("line unknown"): + ip.run_cell("raise SyntaxError()") diff --git a/IPython/core/ultratb.py b/IPython/core/ultratb.py index 991734f..7e68846 100644 --- a/IPython/core/ultratb.py +++ b/IPython/core/ultratb.py @@ -556,7 +556,8 @@ class ListTB(TBTools): have_filedata = True #print 'filename is',filename # dbg if not value.filename: value.filename = "" - list.append('%s File %s"%s"%s, line %s%d%s\n' % \ + if not value.lineno: value.lineno = "unknown" + list.append('%s File %s"%s"%s, line %s%s%s\n' % \ (Colors.normalEm, Colors.filenameEm, py3compat.cast_unicode(value.filename), Colors.normalEm, Colors.linenoEm, value.lineno, Colors.Normal ))