]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 85817,85904 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Fri, 29 Oct 2010 04:02:30 +0000 (04:02 +0000)
committerBenjamin Peterson <benjamin@python.org>
Fri, 29 Oct 2010 04:02:30 +0000 (04:02 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r85817 | benjamin.peterson | 2010-10-23 22:41:46 -0500 (Sat, 23 Oct 2010) | 1 line

  tighten loop
........
  r85904 | benjamin.peterson | 2010-10-28 22:28:14 -0500 (Thu, 28 Oct 2010) | 1 line

  decrement offset when it points to a newline (#10186 followup)
........

Lib/test/test_traceback.py
Python/pythonrun.c

index d39322f2d9d4a917b159c2b5464ae36709156fc3..b2c72626f664501937a7673baca9abe04dec41d7 100644 (file)
@@ -302,6 +302,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 10a1d504a0807317d0299d394e7bcaf15cf4753a..3dbe754d26341d36c5b3ee48cc2a5407e56357be 100644 (file)
@@ -1299,6 +1299,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)
@@ -1318,11 +1320,8 @@ print_error_text(PyObject *f, int offset, const char *text)
     if (offset == -1)
         return;
     PyFile_WriteString("    ", f);
-    offset--;
-    while (offset > 0) {
+    while (--offset > 0)
         PyFile_WriteString(" ", f);
-        offset--;
-    }
     PyFile_WriteString("^\n", f);
 }