gh-105259: Ensure we don't show newline characters for trailing NEWLINE tokens (#105364)

This commit is contained in:
Pablo Galindo Salgado 2023-06-06 13:52:16 +02:00 committed by GitHub
parent 0202aa002e
commit c0a6ed3934
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 5 deletions

View file

@ -243,10 +243,12 @@ tokenizeriter_next(tokenizeriterobject *it)
}
else if (type == NEWLINE) {
Py_DECREF(str);
if (it->tok->start[0] == '\r') {
str = PyUnicode_FromString("\r\n");
} else {
str = PyUnicode_FromString("\n");
if (!it->tok->implicit_newline) {
if (it->tok->start[0] == '\r') {
str = PyUnicode_FromString("\r\n");
} else {
str = PyUnicode_FromString("\n");
}
}
end_col_offset++;
}