[Python-3000-checkins] r56536 - python/branches/p3yk/Lib/traceback.py

kurt.kaiser python-3000-checkins at python.org
Wed Jul 25 04:06:49 CEST 2007


Author: kurt.kaiser
Date: Wed Jul 25 04:06:48 2007
New Revision: 56536

Modified:
   python/branches/p3yk/Lib/traceback.py
Log:
Not all instantiations of SyntaxError set the args attribute.
e.g. symtable.c
Modify format_exception_only() to get SyntaxError attributes directly
instead of unpacking 'args'.


Modified: python/branches/p3yk/Lib/traceback.py
==============================================================================
--- python/branches/p3yk/Lib/traceback.py	(original)
+++ python/branches/p3yk/Lib/traceback.py	Wed Jul 25 04:06:48 2007
@@ -161,7 +161,6 @@
     string in the list.
 
     """
-
     # Gracefully handle (the way Python 2.4 and earlier did) the case of
     # being called with (None, None).
     if etype is None:
@@ -177,27 +176,24 @@
 
     # It was a syntax error; show exactly where the problem was found.
     lines = []
-    try:
-        msg, (filename, lineno, offset, badline) = value.args
-    except Exception:
-        pass
-    else:
-        filename = filename or "<string>"
-        lines.append('  File "%s", line %d\n' % (filename, lineno))
-        if badline is not None:
-            lines.append('    %s\n' % badline.strip())
-            if offset is not None:
-                caretspace = badline[:offset].lstrip()
-                # non-space whitespace (likes tabs) must be kept for alignment
-                caretspace = ((c.isspace() and c or ' ') for c in caretspace)
-                # only three spaces to account for offset1 == pos 0
-                lines.append('   %s^\n' % ''.join(caretspace))
-            value = msg
-    lines.append("%s: %s\n" % (stype, str(msg)))
+    filename = value.filename or "<string>"
+    lineno = str(value.lineno) or '?'
+    lines.append('  File "%s", line %s\n' % (filename, lineno))
+    badline = value.text
+    offset = value.offset
+    if badline is not None:
+        lines.append('    %s\n' % badline.strip())
+        if offset is not None:
+            caretspace = badline[:offset].lstrip()
+            # non-space whitespace (likes tabs) must be kept for alignment
+            caretspace = ((c.isspace() and c or ' ') for c in caretspace)
+            # only three spaces to account for offset1 == pos 0
+            lines.append('   %s^\n' % ''.join(caretspace))
+    msg = value.msg or "<no detail available>"
+    lines.append("%s: %s\n" % (stype, msg))
     return lines
 
 def _format_final_exc_line(etype, value):
-    """Return a list of a single line -- normal case for format_exception_only"""
     valuestr = _some_str(value)
     if value is None or not valuestr:
         line = "%s\n" % etype


More information about the Python-3000-checkins mailing list