diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-07-29 14:18:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-29 14:18:47 (GMT) |
commit | cf52bd0b9b1c1b7ecdd91e1ebebd15ae5c213a2c (patch) | |
tree | 9b1dd786e0081346c2b551b3ed11ddcacb76194b | |
parent | 36fd7b6f01127bc6a8b4a37a363e0aa9cfd76506 (diff) | |
download | cpython-cf52bd0b9b1c1b7ecdd91e1ebebd15ae5c213a2c.zip cpython-cf52bd0b9b1c1b7ecdd91e1ebebd15ae5c213a2c.tar.gz cpython-cf52bd0b9b1c1b7ecdd91e1ebebd15ae5c213a2c.tar.bz2 |
Fix `SyntaxError` indicator printing too many spaces for multi-line strings (GH-14433)
(cherry picked from commit 5b94f3578c662d5f1ee90c0e6b81481d9ec82d89)
Co-authored-by: Anthony Sottile <asottile@umich.edu>
-rw-r--r-- | Lib/test/test_cmd_line_script.py | 14 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2019-06-27-15-01-14.bpo-37433.amNGqr.rst | 1 | ||||
-rw-r--r-- | Parser/tokenizer.c | 2 |
3 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_cmd_line_script.py b/Lib/test/test_cmd_line_script.py index d138ca0..4cc265e 100644 --- a/Lib/test/test_cmd_line_script.py +++ b/Lib/test/test_cmd_line_script.py @@ -601,6 +601,20 @@ class CmdLineTest(unittest.TestCase): self.assertNotIn("\f", text) self.assertIn("\n 1 + 1 = 2\n ^", text) + def test_syntaxerror_multi_line_fstring(self): + script = 'foo = f"""{}\nfoo"""\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) + self.assertEqual( + stderr.splitlines()[-3:], + [ + b' foo = f"""{}', + b' ^', + b'SyntaxError: f-string: empty expression not allowed', + ], + ) + def test_consistent_sys_path_for_direct_execution(self): # This test case ensures that the following all give the same # sys.path configuration: diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-06-27-15-01-14.bpo-37433.amNGqr.rst b/Misc/NEWS.d/next/Core and Builtins/2019-06-27-15-01-14.bpo-37433.amNGqr.rst new file mode 100644 index 0000000..794ddbb --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2019-06-27-15-01-14.bpo-37433.amNGqr.rst @@ -0,0 +1 @@ +Fix ``SyntaxError`` indicator printing too many spaces for multi-line strings - by Anthony Sottile. diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index c2ec659..31fe970 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -956,6 +956,7 @@ tok_nextc(struct tok_state *tok) while (!done) { Py_ssize_t curstart = tok->start == NULL ? -1 : tok->start - tok->buf; + Py_ssize_t cur_multi_line_start = tok->multi_line_start - tok->buf; Py_ssize_t curvalid = tok->inp - tok->buf; Py_ssize_t newsize = curvalid + BUFSIZ; char *newbuf = tok->buf; @@ -968,6 +969,7 @@ tok_nextc(struct tok_state *tok) } tok->buf = newbuf; tok->cur = tok->buf + cur; + tok->multi_line_start = tok->buf + cur_multi_line_start; tok->line_start = tok->cur; tok->inp = tok->buf + curvalid; tok->end = tok->buf + newsize; |