diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-06-07 13:07:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-07 13:07:57 (GMT) |
commit | 117c153d9fda7553a7fb5d342552e48c4b5c1260 (patch) | |
tree | a4b57d34c5c05a62bf07877c27ebb302ab4a3444 /Python/Python-tokenize.c | |
parent | bb6ea7200397d2a9650c5d8c7d08acef11edd39b (diff) | |
download | cpython-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.c | 11 |
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); |