diff options
author | Georg Brandl <georg@python.org> | 2006-03-31 15:59:13 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2006-03-31 15:59:13 (GMT) |
commit | 51dbc4c879160c1ee4cf159595368676ced09500 (patch) | |
tree | b838ce6e1bf1820bc69165ad983770fc749f6b26 | |
parent | 3bf538f13d6c98aba0cadba6b2906816ba2a1704 (diff) | |
download | cpython-51dbc4c879160c1ee4cf159595368676ced09500.zip cpython-51dbc4c879160c1ee4cf159595368676ced09500.tar.gz cpython-51dbc4c879160c1ee4cf159595368676ced09500.tar.bz2 |
traceback now shows error position for all SyntaxError subclasses,
e.g. IndentationError. (bug #1447885)
-rw-r--r-- | Lib/test/test_traceback.py | 10 | ||||
-rw-r--r-- | Lib/traceback.py | 2 |
2 files changed, 11 insertions, 1 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 29a120f..269c628 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -23,6 +23,9 @@ class TracebackCases(unittest.TestCase): def syntax_error_without_caret(self): # XXX why doesn't compile raise the same traceback? import test.badsyntax_nocaret + + def syntax_error_bad_indentation(self): + compile("def spam():\n print 1\n print 2", "?", "exec") def test_caret(self): err = self.get_exception_format(self.syntax_error_with_caret, @@ -40,6 +43,13 @@ class TracebackCases(unittest.TestCase): self.assert_(len(err) == 3) 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): import sys, os, tempfile, time diff --git a/Lib/traceback.py b/Lib/traceback.py index d4a4011..4047ca5 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -165,7 +165,7 @@ def format_exception_only(etype, value): if value is None: list.append(str(stype) + '\n') else: - if etype is SyntaxError: + if issubclass(etype, SyntaxError): try: msg, (filename, lineno, offset, line) = value except: |