]> granicus.if.org Git - python/commitdiff
Issue #17825: Cursor ^ is correctly positioned for SyntaxError and IndentationError.
authorFlorent Xicluna <florent.xicluna@gmail.com>
Wed, 22 Jan 2014 00:16:25 +0000 (01:16 +0100)
committerFlorent Xicluna <florent.xicluna@gmail.com>
Wed, 22 Jan 2014 00:16:25 +0000 (01:16 +0100)
1  2 
Lib/test/test_traceback.py
Lib/traceback.py
Misc/NEWS

Simple merge
index 3b2cae748e97d24242e46a1cdbdbe2008b596a8b,f33fced7a9d70e12440bd9d1fb30ba385fd732fb..faf593a7354968cad96dcb2b12be714baa069691
@@@ -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 "<no detail available>"
 -    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)
diff --cc Misc/NEWS
Simple merge