gh-94869: Fix the location in some expressions for multi-line f-string ast nodes (#94895)

This commit is contained in:
Pablo Galindo Salgado 2022-07-16 19:51:53 +01:00 committed by GitHub
parent 4b4439daed
commit 2e9da8e352
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 3 deletions

View file

@ -326,6 +326,9 @@ fstring_find_expr_location(Token *parent, const char* expr_start, char *expr_str
start--;
}
*p_cols += (int)(expr_start - start);
if (*start == '\n') {
*p_cols -= 1;
}
}
/* adjust the start based on the number of newlines encountered
before the f-string expression */
@ -416,7 +419,7 @@ fstring_compile_expr(Parser *p, const char *expr_start, const char *expr_end,
NULL, p->arena);
p2->starting_lineno = t->lineno + lines;
p2->starting_col_offset = t->col_offset + cols;
p2->starting_col_offset = lines != 0 ? cols : t->col_offset + cols;
expr = _PyPegen_run_parser(p2);