mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-94869: Fix the location in some expressions for multi-line f-string ast nodes (#94895)
This commit is contained in:
parent
4b4439daed
commit
2e9da8e352
3 changed files with 37 additions and 3 deletions
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue