]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport Tim's checkin 1.26 (patch probably by Michael Hudson, not Hundson):
authorThomas Wouters <thomas@python.org>
Wed, 27 Jun 2001 14:07:50 +0000 (14:07 +0000)
committerThomas Wouters <thomas@python.org>
Wed, 27 Jun 2001 14:07:50 +0000 (14:07 +0000)
SF bug 431772:  traceback.print_exc() causes traceback
Patch from Michael Hundson.
format_exception_only() blew up when trying to report a SyntaxError
from a string input (line is None in this case, but it assumed a string).

Lib/traceback.py

index a758349f91f1e99aacc0073b759e1ce78856df5b..70b16067b9ddc16b6952a9dd37c573d4d86b6b9d 100644 (file)
@@ -171,19 +171,20 @@ def format_exception_only(etype, value):
                 if not filename: filename = "<string>"
                 list.append('  File "%s", line %d\n' %
                             (filename, lineno))
-                i = 0
-                while i < len(line) and line[i].isspace():
-                    i = i+1
-                list.append('    %s\n' % line.strip())
-                if offset is not None:
-                    s = '    '
-                    for c in line[i:offset-1]:
-                        if c.isspace():
-                            s = s + c
-                        else:
-                            s = s + ' '
-                    list.append('%s^\n' % s)
-                value = msg
+                if line is not None:
+                    i = 0
+                    while i < len(line) and line[i].isspace():
+                        i = i+1
+                    list.append('    %s\n' % line.strip())
+                    if offset is not None:
+                        s = '    '
+                        for c in line[i:offset-1]:
+                            if c.isspace():
+                                s = s + c
+                            else:
+                                s = s + ' '
+                        list.append('%s^\n' % s)
+                    value = msg
         s = _some_str(value)
         if s:
             list.append('%s: %s\n' % (str(stype), s))