Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a17a2f5 commit c471ca4Copy full SHA for c471ca4
2 files changed
Lib/test/test_tokenize.py
@@ -39,20 +39,22 @@ def test_basic(self):
39
""")
40
self.check_tokenize("if False:\n"
41
" # NL\n"
42
+ " \n"
43
" True = False # NEWLINE\n", """\
44
NAME 'if' (1, 0) (1, 2)
45
NAME 'False' (1, 3) (1, 8)
46
OP ':' (1, 8) (1, 9)
47
NEWLINE '\\n' (1, 9) (1, 10)
48
COMMENT '# NL' (2, 4) (2, 8)
49
NL '\\n' (2, 8) (2, 9)
- INDENT ' ' (3, 0) (3, 4)
50
- NAME 'True' (3, 4) (3, 8)
51
- OP '=' (3, 9) (3, 10)
52
- NAME 'False' (3, 11) (3, 16)
53
- COMMENT '# NEWLINE' (3, 17) (3, 26)
54
- NEWLINE '\\n' (3, 26) (3, 27)
55
- DEDENT '' (4, 0) (4, 0)
+ NL '\\n' (3, 4) (3, 5)
+ INDENT ' ' (4, 0) (4, 4)
+ NAME 'True' (4, 4) (4, 8)
+ OP '=' (4, 9) (4, 10)
+ NAME 'False' (4, 11) (4, 16)
+ COMMENT '# NEWLINE' (4, 17) (4, 26)
56
+ NEWLINE '\\n' (4, 26) (4, 27)
57
+ DEDENT '' (5, 0) (5, 0)
58
59
indent_error_file = b"""\
60
def k(x):
Lib/tokenize.py
@@ -560,13 +560,11 @@ def _tokenize(readline, encoding):
560
if line[pos] in '#\r\n': # skip comments or blank lines
561
if line[pos] == '#':
562
comment_token = line[pos:].rstrip('\r\n')
563
- nl_pos = pos + len(comment_token)
564
yield TokenInfo(COMMENT, comment_token,
565
(lnum, pos), (lnum, pos + len(comment_token)), line)
566
- yield TokenInfo(NL, line[nl_pos:],
567
- (lnum, nl_pos), (lnum, len(line)), line)
568
- else:
569
- yield TokenInfo((NL, COMMENT)[line[pos] == '#'], line[pos:],
+ pos += len(comment_token)
+
+ yield TokenInfo(NL, line[pos:],
570
(lnum, pos), (lnum, len(line)), line)
571
continue
572
0 commit comments