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

This commit is contained in:
Pablo Galindo Salgado 2023-06-07 13:31:48 +01:00 committed by GitHub
parent a24a780d93
commit 7279fb6408
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);