@@ -1326,13 +1326,13 @@ def build_tokens_line(self):
1326
1326
fill = self .lines [end_row - 1 ][end :start ]
1327
1327
logical .append (fill )
1328
1328
length += len (fill )
1329
+ length += len (text )
1329
1330
mapping .append ((length , token ))
1330
1331
logical .append (text )
1331
- length += len (text )
1332
1332
previous = token
1333
1333
self .logical_line = '' .join (logical )
1334
1334
self .noqa = comments and noqa ('' .join (comments ))
1335
- return mapping or [(0 , self .tokens [0 ])]
1335
+ return mapping or [(len ( self . tokens [ 0 ][ 1 ]) , self .tokens [0 ])]
1336
1336
1337
1337
def check_logical (self ):
1338
1338
"""Build a line from tokens and run all logical checks on it."""
@@ -1354,10 +1354,10 @@ def check_logical(self):
1354
1354
(li_number , li_offset ) = offset
1355
1355
else :
1356
1356
for (token_offset , token ) in mapping :
1357
- if offset < token_offset :
1357
+ if offset <= token_offset :
1358
1358
break
1359
- li_number = token [2 ][0 ]
1360
- li_offset = (token [2 ][1 ] + offset - token_offset )
1359
+ li_number = token [3 ][0 ]
1360
+ li_offset = (token [3 ][1 ] + offset - token_offset )
1361
1361
self .report_error (li_number , li_offset , text , check )
1362
1362
if self .logical_line :
1363
1363
self .previous_indent_level = self .indent_level
@@ -1460,8 +1460,10 @@ def check_all(self, expected=None, line_offset=0):
1460
1460
elif COMMENT_WITH_NL and token_type == tokenize .COMMENT :
1461
1461
if len (self .tokens ) == 1 :
1462
1462
# The comment also ends a physical line
1463
- text = text .rstrip ('\r \n ' )
1464
- self .tokens = [(token_type , text ) + token [2 :]]
1463
+ token = list (token )
1464
+ token [1 ] = text .rstrip ('\r \n ' )
1465
+ token [3 ] = (token [2 ][0 ], token [2 ][1 ] + len (token [1 ]))
1466
+ self .tokens = [tuple (token )]
1465
1467
self .check_logical ()
1466
1468
return self .report .get_file_results ()
1467
1469
0 commit comments