summaryrefslogtreecommitdiffstats
path: root/Lib/tokenize.py
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2021-07-31 01:17:09 (GMT)
committerGitHub <noreply@github.com>2021-07-31 01:17:09 (GMT)
commitb6bde9fc42aecad5be0457198d17cfe7b481ad79 (patch)
treeec5e777de20072b7bf98d8101adf07e942cde4e8 /Lib/tokenize.py
parente63e6311aa258a5f3f49a7aed9fdde445fd384d6 (diff)
downloadcpython-b6bde9fc42aecad5be0457198d17cfe7b481ad79.zip
cpython-b6bde9fc42aecad5be0457198d17cfe7b481ad79.tar.gz
cpython-b6bde9fc42aecad5be0457198d17cfe7b481ad79.tar.bz2
bpo-44667: Treat correctly lines ending with comments and no newlines in the Python tokenizer (GH-27499)
Diffstat (limited to 'Lib/tokenize.py')
-rw-r--r--Lib/tokenize.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/Lib/tokenize.py b/Lib/tokenize.py
index 42c1f10..7d7736f 100644
--- a/Lib/tokenize.py
+++ b/Lib/tokenize.py
@@ -604,7 +604,7 @@ def _tokenize(readline, encoding):
pos += 1
# Add an implicit NEWLINE if the input doesn't end in one
- if last_line and last_line[-1] not in '\r\n':
+ if last_line and last_line[-1] not in '\r\n' and not last_line.strip().startswith("#"):
yield TokenInfo(NEWLINE, '', (lnum - 1, len(last_line)), (lnum - 1, len(last_line) + 1), '')
for indent in indents[1:]: # pop remaining indent levels
yield TokenInfo(DEDENT, '', (lnum, 0), (lnum, 0), '')