[Python-checkins] r43486 - in python/trunk/Lib: test/test_traceback.py traceback.py

georg.brandl python-checkins at python.org
Fri Mar 31 17:59:14 CEST 2006


Author: georg.brandl
Date: Fri Mar 31 17:59:13 2006
New Revision: 43486

Modified:
   python/trunk/Lib/test/test_traceback.py
   python/trunk/Lib/traceback.py
Log:
traceback now shows error position for all SyntaxError subclasses, 
e.g. IndentationError. (bug #1447885)



Modified: python/trunk/Lib/test/test_traceback.py
==============================================================================
--- python/trunk/Lib/test/test_traceback.py	(original)
+++ python/trunk/Lib/test/test_traceback.py	Fri Mar 31 17:59:13 2006
@@ -23,6 +23,9 @@
     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 @@
         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
 

Modified: python/trunk/Lib/traceback.py
==============================================================================
--- python/trunk/Lib/traceback.py	(original)
+++ python/trunk/Lib/traceback.py	Fri Mar 31 17:59:13 2006
@@ -165,7 +165,7 @@
     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:


More information about the Python-checkins mailing list