mirror of
https://github.com/python/cpython.git
synced 2025-08-17 15:21:26 +00:00
Fix SyntaxError
indicator printing too many spaces for multi-line strings (GH-14433)
(cherry picked from commit 5b94f3578c
)
Co-authored-by: Anthony Sottile <asottile@umich.edu>
This commit is contained in:
parent
36fd7b6f01
commit
cf52bd0b9b
3 changed files with 17 additions and 0 deletions
|
@ -601,6 +601,20 @@ class CmdLineTest(unittest.TestCase):
|
||||||
self.assertNotIn("\f", text)
|
self.assertNotIn("\f", text)
|
||||||
self.assertIn("\n 1 + 1 = 2\n ^", 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):
|
def test_consistent_sys_path_for_direct_execution(self):
|
||||||
# This test case ensures that the following all give the same
|
# This test case ensures that the following all give the same
|
||||||
# sys.path configuration:
|
# sys.path configuration:
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix ``SyntaxError`` indicator printing too many spaces for multi-line strings - by Anthony Sottile.
|
|
@ -956,6 +956,7 @@ tok_nextc(struct tok_state *tok)
|
||||||
while (!done) {
|
while (!done) {
|
||||||
Py_ssize_t curstart = tok->start == NULL ? -1 :
|
Py_ssize_t curstart = tok->start == NULL ? -1 :
|
||||||
tok->start - tok->buf;
|
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 curvalid = tok->inp - tok->buf;
|
||||||
Py_ssize_t newsize = curvalid + BUFSIZ;
|
Py_ssize_t newsize = curvalid + BUFSIZ;
|
||||||
char *newbuf = tok->buf;
|
char *newbuf = tok->buf;
|
||||||
|
@ -968,6 +969,7 @@ tok_nextc(struct tok_state *tok)
|
||||||
}
|
}
|
||||||
tok->buf = newbuf;
|
tok->buf = newbuf;
|
||||||
tok->cur = tok->buf + cur;
|
tok->cur = tok->buf + cur;
|
||||||
|
tok->multi_line_start = tok->buf + cur_multi_line_start;
|
||||||
tok->line_start = tok->cur;
|
tok->line_start = tok->cur;
|
||||||
tok->inp = tok->buf + curvalid;
|
tok->inp = tok->buf + curvalid;
|
||||||
tok->end = tok->buf + newsize;
|
tok->end = tok->buf + newsize;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue