[3.12] gh-105435: Fix spurious NEWLINE token if file ends with comment without a newline (GH-105442) (#105444)

This commit is contained in:
Miss Islington (bot) 2023-06-07 06:07:57 -07:00 committed by GitHub
parent bb6ea72003
commit 117c153d9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 5 deletions

View file

@ -247,6 +247,17 @@ tokenizeriter_next(tokenizeriterobject *it)
}
end_col_offset++;
}
else if (type == NL) {
if (it->tok->implicit_newline) {
Py_DECREF(str);
str = PyUnicode_FromString("");
}
}
if (str == NULL) {
Py_DECREF(line);
goto exit;
}
}
result = Py_BuildValue("(iN(nn)(nn)N)", type, str, lineno, col_offset, end_lineno, end_col_offset, line);