commit 975925e7b861625f929d7497c153207c1fe801e2 Author: Michael Layzell Date: Fri Nov 20 15:13:23 2015 -0500 Issue #25677: Correct syntax error caret for indented blocks. diff --git a/Lib/test/test_cmd_line_script.py b/Lib/test/test_cmd_line_script.py index fda3e62..cfb2571 100644 --- a/Lib/test/test_cmd_line_script.py +++ b/Lib/test/test_cmd_line_script.py @@ -10,6 +10,7 @@ import os import os.path import py_compile import subprocess +import io import textwrap from test import support @@ -471,6 +472,29 @@ class CmdLineTest(unittest.TestCase): text = stderr.decode('ascii') self.assertEqual(text, "some text") + def test_syntaxerror_unindented_caret_position(self): + script = textwrap.dedent("""\ + 1 + 1 = 2 + """) + with support.temp_dir() as script_dir: + script_name = _make_test_script(script_dir, 'script', script) + exitcode, stdout, stderr = assert_python_failure(script_name) + text = io.TextIOWrapper(io.BytesIO(stderr), 'ascii').read() + # Confirm that the caret is located under the first 1 character + self.assertRegex(text, r"\n 1 \+ 1 = 2\n \^") + + def test_syntaxerror_indented_caret_position(self): + script = textwrap.dedent("""\ + if True: + 1 + 1 = 2 + """) + with support.temp_dir() as script_dir: + script_name = _make_test_script(script_dir, 'script', script) + exitcode, stdout, stderr = assert_python_failure(script_name) + text = io.TextIOWrapper(io.BytesIO(stderr), 'ascii').read() + # Confirm that the caret is located under the first 1 character + self.assertRegex(text, r"\n 1 \+ 1 = 2\n \^") + def test_main(): support.run_unittest(CmdLineTest) diff --git a/Python/errors.c b/Python/errors.c index aed2bdc..5a603ad 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -1098,8 +1098,6 @@ err_programtext(FILE *fp, int lineno) if (i == lineno) { char *p = linebuf; PyObject *res; - while (*p == ' ' || *p == '\t' || *p == '\014') - p++; res = PyUnicode_FromString(p); if (res == NULL) PyErr_Clear();