diff options
Diffstat (limited to 'Lib/traceback.py')
-rw-r--r-- | Lib/traceback.py | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/Lib/traceback.py b/Lib/traceback.py index 437e29b..11ece25 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -161,7 +161,6 @@ def format_exception_only(etype, value): 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,28 +176,24 @@ def format_exception_only(etype, value): # 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(_format_final_exc_line(stype, value)) + 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 |