bpo-46237: Fix the line number of tokenizer errors inside f-strings (… · donbarbos/cpython@6fa8b2c · GitHub
Skip to content

Commit 6fa8b2c

Browse files
authored
bpo-46237: Fix the line number of tokenizer errors inside f-strings (pythonGH-30463)
1 parent d81182b commit 6fa8b2c

4 files changed

Lines changed: 22 additions & 5 deletions

File tree

Lib/test/test_exceptions.py

Lines changed: 12 additions & 0 deletions
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix the line number of tokenizer errors inside f-strings. Patch by Pablo
2+
Galindo.

Parser/pegen.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ initialize_token(Parser *p, Token *token, const char *start, const char *end, in
179179
int col_offset = (start != NULL && start >= line_start) ? (int)(start - line_start) : -1;
180180
int end_col_offset = (end != NULL && end >= p->tok->line_start) ? (int)(end - p->tok->line_start) : -1;
181181

182-
token->lineno = p->starting_lineno + lineno;
183-
token->col_offset = p->tok->lineno == 1 ? p->starting_col_offset + col_offset : col_offset;
184-
token->end_lineno = p->starting_lineno + end_lineno;
185-
token->end_col_offset = p->tok->lineno == 1 ? p->starting_col_offset + end_col_offset : end_col_offset;
182+
token->lineno = lineno;
183+
token->col_offset = p->tok->lineno == p->starting_lineno ? p->starting_col_offset + col_offset : col_offset;
184+
token->end_lineno = end_lineno;
185+
token->end_col_offset = p->tok->lineno == p->starting_lineno ? p->starting_col_offset + end_col_offset : end_col_offset;
186186

187187
p->fill += 1;
188188

Parser/string_parser.c

Lines changed: 4 additions & 1 deletion

0 commit comments

Comments
 (0)