summaryrefslogtreecommitdiffstats
path: root/Python/Python-tokenize.c
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-06-07 13:07:57 (GMT)
committerGitHub <noreply@github.com>2023-06-07 13:07:57 (GMT)
commit117c153d9fda7553a7fb5d342552e48c4b5c1260 (patch)
treea4b57d34c5c05a62bf07877c27ebb302ab4a3444 /Python/Python-tokenize.c
parentbb6ea7200397d2a9650c5d8c7d08acef11edd39b (diff)
downloadcpython-117c153d9fda7553a7fb5d342552e48c4b5c1260.zip
cpython-117c153d9fda7553a7fb5d342552e48c4b5c1260.tar.gz
cpython-117c153d9fda7553a7fb5d342552e48c4b5c1260.tar.bz2
[3.12] gh-105435: Fix spurious NEWLINE token if file ends with comment without a newline (GH-105442) (#105444)
Diffstat (limited to 'Python/Python-tokenize.c')
-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);