traceback now shows error position for all SyntaxError subclasses,

e.g. IndentationError. (bug #1447885)
This commit is contained in:
Georg Brandl 2006-03-31 15:59:13 +00:00
parent 3bf538f13d
commit 51dbc4c879
2 changed files with 11 additions and 1 deletions

View File

@ -24,6 +24,9 @@ class TracebackCases(unittest.TestCase):
# XXX why doesn't compile raise the same traceback? # XXX why doesn't compile raise the same traceback?
import test.badsyntax_nocaret import test.badsyntax_nocaret
def syntax_error_bad_indentation(self):
compile("def spam():\n print 1\n print 2", "?", "exec")
def test_caret(self): def test_caret(self):
err = self.get_exception_format(self.syntax_error_with_caret, err = self.get_exception_format(self.syntax_error_with_caret,
SyntaxError) SyntaxError)
@ -40,6 +43,13 @@ class TracebackCases(unittest.TestCase):
self.assert_(len(err) == 3) self.assert_(len(err) == 3)
self.assert_(err[1].strip() == "[x for x in x] = x") self.assert_(err[1].strip() == "[x for x in x] = x")
def test_bad_indentation(self):
err = self.get_exception_format(self.syntax_error_bad_indentation,
IndentationError)
self.assert_(len(err) == 4)
self.assert_("^" in err[2])
self.assert_(err[1].strip() == "print 2")
def test_bug737473(self): def test_bug737473(self):
import sys, os, tempfile, time import sys, os, tempfile, time

View File

@ -165,7 +165,7 @@ def format_exception_only(etype, value):
if value is None: if value is None:
list.append(str(stype) + '\n') list.append(str(stype) + '\n')
else: else:
if etype is SyntaxError: if issubclass(etype, SyntaxError):
try: try:
msg, (filename, lineno, offset, line) = value msg, (filename, lineno, offset, line) = value
except: except: