mirror of
https://github.com/python/cpython.git
synced 2025-07-19 09:15:34 +00:00
gh-104825: Remove implicit newline in the line attribute in tokens emitted in the tokenize module (#104846)
This commit is contained in:
parent
c45701e9ef
commit
c8cf9b42eb
5 changed files with 14 additions and 8 deletions
|
@ -123,6 +123,8 @@ _tokenizer_error(struct tok_state *tok)
|
|||
int result = 0;
|
||||
|
||||
Py_ssize_t size = tok->inp - tok->buf;
|
||||
assert(tok->buf[size-1] == '\n');
|
||||
size -= 1; // Remove the newline character from the end of the line
|
||||
error_line = PyUnicode_DecodeUTF8(tok->buf, size, "replace");
|
||||
if (!error_line) {
|
||||
result = -1;
|
||||
|
@ -193,6 +195,8 @@ tokenizeriter_next(tokenizeriterobject *it)
|
|||
}
|
||||
|
||||
Py_ssize_t size = it->tok->inp - it->tok->buf;
|
||||
assert(it->tok->buf[size-1] == '\n');
|
||||
size -= 1; // Remove the newline character from the end of the line
|
||||
PyObject *line = PyUnicode_DecodeUTF8(it->tok->buf, size, "replace");
|
||||
if (line == NULL) {
|
||||
Py_DECREF(str);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue