diff options
author | Martin Panter <vadmium+py@gmail.com> | 2016-12-19 06:46:12 (GMT) |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2016-12-19 06:46:12 (GMT) |
commit | b46edf35f3dea8c828b45d6ae02d2c716dd1d0ea (patch) | |
tree | 0074b12ae7e8aada22b8753d69f66abde9128412 | |
parent | 932ee73188c73bbe63834f69566a4f188fbf43a7 (diff) | |
parent | 619555d77bba05c71d9ef0a1c29ec53a17ebe2ca (diff) | |
download | cpython-b46edf35f3dea8c828b45d6ae02d2c716dd1d0ea.zip cpython-b46edf35f3dea8c828b45d6ae02d2c716dd1d0ea.tar.gz cpython-b46edf35f3dea8c828b45d6ae02d2c716dd1d0ea.tar.bz2 |
Issue #25677: Merge SyntaxError caret positioning from 3.6
-rw-r--r-- | Lib/test/test_cmd_line_script.py | 33 | ||||
-rw-r--r-- | Misc/ACKS | 1 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Python/errors.c | 5 | ||||
-rw-r--r-- | Python/pythonrun.c | 2 |
5 files changed, 39 insertions, 5 deletions
diff --git a/Lib/test/test_cmd_line_script.py b/Lib/test/test_cmd_line_script.py index 38cb2e2..e058ecd 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 @@ -539,6 +540,38 @@ class CmdLineTest(unittest.TestCase): text = stderr.decode('ascii') self.assertEqual(text, "some text") + def test_syntaxerror_unindented_caret_position(self): + script = "1 + 1 = 2\n" + 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.assertIn("\n 1 + 1 = 2\n ^", text) + + 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.assertIn("\n 1 + 1 = 2\n ^", text) + + # Try the same with a form feed at the start of the indented line + script = ( + "if True:\n" + "\f 1 + 1 = 2\n" + ) + 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() + self.assertNotIn("\f", text) + self.assertIn("\n 1 + 1 = 2\n ^", text) + def test_main(): support.run_unittest(CmdLineTest) @@ -852,6 +852,7 @@ Julia Lawall Chris Lawrence Mark Lawrence Chris Laws +Michael Layzell Michael Lazar Brian Leair Mathieu Leduc-Hamel @@ -10,6 +10,9 @@ What's New in Python 3.7.0 alpha 1 Core and Builtins ----------------- +- Issue #25677: Correct the positioning of the syntax error caret for + indented blocks. Based on patch by Michael Layzell. + - Issue #29000: Fixed bytes formatting of octals with zero padding in alternate form. diff --git a/Python/errors.c b/Python/errors.c index 35c9e3a..3785e69 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -1138,11 +1138,8 @@ err_programtext(FILE *fp, int lineno) } fclose(fp); if (i == lineno) { - char *p = linebuf; PyObject *res; - while (*p == ' ' || *p == '\t' || *p == '\014') - p++; - res = PyUnicode_FromString(p); + res = PyUnicode_FromString(linebuf); if (res == NULL) PyErr_Clear(); return res; diff --git a/Python/pythonrun.c b/Python/pythonrun.c index b862e2b..5bddbad 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -528,7 +528,7 @@ print_error_text(PyObject *f, int offset, PyObject *text_obj) offset -= (int)(nl+1-text); text = nl+1; } - while (*text == ' ' || *text == '\t') { + while (*text == ' ' || *text == '\t' || *text == '\f') { text++; offset--; } |