summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2023-06-07 12:31:48 (GMT)
committerGitHub <noreply@github.com>2023-06-07 12:31:48 (GMT)
commit7279fb64089abc73c03247fb8191082ee42a9671 (patch)
treea92d02173f8156e902832ac9884a52f525656fa4 /Python
parenta24a780d937109a0982d807473ae410cc75b0e3b (diff)
downloadcpython-7279fb64089abc73c03247fb8191082ee42a9671.zip
cpython-7279fb64089abc73c03247fb8191082ee42a9671.tar.gz
cpython-7279fb64089abc73c03247fb8191082ee42a9671.tar.bz2
gh-105435: Fix spurious NEWLINE token if file ends with comment without a newline (#105442)
Diffstat (limited to 'Python')
-rw-r--r--Python/Python-tokenize.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/Python/Python-tokenize.c b/Python/Python-tokenize.c
index 4d21793..83a129c 100644
--- a/Python/Python-tokenize.c
+++ b/Python/Python-tokenize.c
@@ -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);