]> granicus.if.org Git - python/commitdiff
decrement offset when it points to a newline (#10186 followup)
authorBenjamin Peterson <benjamin@python.org>
Fri, 29 Oct 2010 03:28:14 +0000 (03:28 +0000)
committerBenjamin Peterson <benjamin@python.org>
Fri, 29 Oct 2010 03:28:14 +0000 (03:28 +0000)
Lib/test/test_traceback.py
Python/pythonrun.c

index e4ae4abcc9ac14797c5fafd0aa3d32f69ec650fb..75678497bf3bfac693eac270fab1bf4ac4d14446 100644 (file)
@@ -295,6 +295,10 @@ class BaseExceptionReportingTests:
             raise SyntaxError('', ('', 0, 5, 'hello'))
         msg = self.get_report(e).splitlines()
         self.assertEqual(msg[-2], "        ^")
+        def e():
+            exec("x = 5 | 4 |")
+        msg = self.get_report(e).splitlines()
+        self.assertEqual(msg[-2], '              ^')
 
 
 class PyExcReportingTests(BaseExceptionReportingTests, unittest.TestCase):
index 1b0a84bd6572a8300eefba55d562f9842bf4a8f1..33dd11bc88595ac3ec84a667178d37f25cb2ab2b 100644 (file)
@@ -1344,6 +1344,8 @@ print_error_text(PyObject *f, int offset, const char *text)
 {
     char *nl;
     if (offset >= 0) {
+        if (offset > 0 && offset == strlen(text) && text[offset - 1] == '\n')
+            offset--;
         for (;;) {
             nl = strchr(text, '\n');
             if (nl == NULL || nl-text >= offset)
@@ -1363,7 +1365,7 @@ print_error_text(PyObject *f, int offset, const char *text)
     if (offset == -1)
         return;
     PyFile_WriteString("    ", f);
-    while (--offset)
+    while (--offset > 0)
         PyFile_WriteString(" ", f);
     PyFile_WriteString("^\n", f);
 }