mirror of
https://github.com/python/cpython.git
synced 2025-08-23 10:16:01 +00:00
[3.12] gh-104825: Remove implicit newline in the line attribute in tokens emitted in the tokenize module (GH-104846). (#104850)
(cherry picked from commit c8cf9b42eb
)
This commit is contained in:
parent
2d685eca8a
commit
3d2ed8991f
4 changed files with 12 additions and 6 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