diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2014-01-22 01:11:43 +0100 |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2014-01-22 01:11:43 +0100 |
commit | 758fa5ea819d4301afed5049fa1186f275c4f801 (patch) | |
tree | 9558890b06702644883bbc0171c2dad9ca0320c9 /Lib/traceback.py | |
parent | Issue #20246: Fix test failures on FreeBSD. Patch by Ryan Smith-Roberts. (diff) | |
download | cpython-758fa5ea819d4301afed5049fa1186f275c4f801.tar.gz cpython-758fa5ea819d4301afed5049fa1186f275c4f801.tar.bz2 cpython-758fa5ea819d4301afed5049fa1186f275c4f801.zip |
Issue #17825: Cursor ^ is correctly positioned for SyntaxError and IndentationError.
Diffstat (limited to 'Lib/traceback.py')
-rw-r--r-- | Lib/traceback.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/traceback.py b/Lib/traceback.py index b13bfe2497c..f33fced7a9d 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -227,11 +227,12 @@ def format_exception_only(etype, value): if badline is not None: lines.append(' %s\n' % badline.strip()) if offset is not None: - caretspace = badline.rstrip('\n')[:offset].lstrip() + caretspace = badline.rstrip('\n') + offset = min(len(caretspace), offset) - 1 + caretspace = caretspace[: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)) + lines.append(' %s^\n' % ''.join(caretspace)) msg = value.msg or "<no detail available>" lines.append("%s: %s\n" % (stype, msg)) return lines |