Skip to content

Commit dee8cf3

Browse files
committed
Derive encoding error columns from the reporting cursor
1 parent 3be14e2 commit dee8cf3

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

Parser/tokenizer/helpers.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,9 @@ _PyTokenizer_ensure_utf8(const char *line, struct tok_state *tok, int lineno)
334334
}
335335
}
336336
if (badchar) {
337-
int col_offset = (int)(badchar - line_start) + 1;
338337
_PyTokenizer_syntaxerror_at(
339-
tok, line_start, badchar - line_start, lineno,
340-
col_offset, col_offset,
338+
tok, line_start, badchar - line_start + 1, lineno,
339+
-1, -1,
341340
"Non-UTF-8 code starting with '\\x%.2x'"
342341
"%s%V on line %i, "
343342
"but no encoding declared; "

Parser/tokenizer/helpers.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#include "../lexer/state.h"
77

88
int _PyTokenizer_syntaxerror(struct tok_state *tok, const char *format, ...);
9+
/* Positive range columns are 1-based byte columns. A start column of -1
10+
derives the character column from the reporting cursor; an end column of
11+
-1 uses the start column. */
912
int _PyTokenizer_syntaxerror_known_range(struct tok_state *tok, int col_offset, int end_col_offset, const char *format, ...);
1013
int _PyTokenizer_syntaxerror_at(
1114
struct tok_state *tok, const char *line_start, Py_ssize_t cursor_offset,

0 commit comments

Comments
 (0)