From: Florent Xicluna Date: Wed, 22 Jan 2014 00:16:25 +0000 (+0100) Subject: Issue #17825: Cursor ^ is correctly positioned for SyntaxError and IndentationError. X-Git-Tag: v3.4.0b3~65 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=45e124e26d43d4618d2686b5323c322aa25566b6;p=python Issue #17825: Cursor ^ is correctly positioned for SyntaxError and IndentationError. --- 45e124e26d43d4618d2686b5323c322aa25566b6 diff --cc Lib/traceback.py index 3b2cae748e,f33fced7a9..faf593a735 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@@ -222,15 -225,17 +222,16 @@@ def _format_exception_only_iter(etype, badline = value.text offset = value.offset if badline is not None: - lines.append(' %s\n' % badline.strip()) + 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)) - lines.append(' %s^\n' % ''.join(caretspace)) ++ yield ' {}^\n'.format(''.join(caretspace)) msg = value.msg or "" - lines.append("%s: %s\n" % (stype, msg)) - return lines + yield "{}: {}\n".format(stype, msg) def _format_final_exc_line(etype, value): valuestr = _some_str(value)