From 995d9b92979768125ced4da3a56f755bcdf80f6e Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sat, 12 Jan 2019 20:05:13 -0800 Subject: bpo-16806: Fix `lineno` and `col_offset` for multi-line string tokens (GH-10021) --- Python/ast.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'Python/ast.c') diff --git a/Python/ast.c b/Python/ast.c index 69dfe3c3c4..d71f44a6db 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -4284,9 +4284,13 @@ fstring_fix_node_location(const node *parent, node *n, char *expr_str) start--; } cols += (int)(substr - start); - /* Fix lineno in mulitline strings. */ - while ((substr = strchr(substr + 1, '\n'))) - lines--; + /* adjust the start based on the number of newlines encountered + before the f-string expression */ + for (char* p = parent->n_str; p < substr; p++) { + if (*p == '\n') { + lines++; + } + } } } fstring_shift_node_locations(n, lines, cols); -- cgit v1.2.1