summaryrefslogtreecommitdiff
path: root/Lib/traceback.py
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2014-01-22 01:16:25 +0100
committerFlorent Xicluna <florent.xicluna@gmail.com>2014-01-22 01:16:25 +0100
commit45e124e26d43d4618d2686b5323c322aa25566b6 (patch)
treea9e3d1f32968eab28c098f48afa0dbf4c36d8528 /Lib/traceback.py
parentf1e4fdcf16f84fe1b065fb7d65390d9e2724afa9 (diff)
parent758fa5ea819d4301afed5049fa1186f275c4f801 (diff)
downloadcpython-git-45e124e26d43d4618d2686b5323c322aa25566b6.tar.gz
Issue #17825: Cursor ^ is correctly positioned for SyntaxError and IndentationError.
Diffstat (limited to 'Lib/traceback.py')
-rw-r--r--Lib/traceback.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/traceback.py b/Lib/traceback.py
index 3b2cae748e..faf593a735 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -224,11 +224,12 @@ def _format_exception_only_iter(etype, value):
if badline is not None:
yield ' {}\n'.format(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
- yield ' {}^\n'.format(''.join(caretspace))
+ yield ' {}^\n'.format(''.join(caretspace))
msg = value.msg or "<no detail available>"
yield "{}: {}\n".format(stype, msg)