@@ -1326,13 +1326,13 @@ def build_tokens_line(self):
13261326 fill = self .lines [end_row - 1 ][end :start ]
13271327 logical .append (fill )
13281328 length += len (fill )
1329+ length += len (text )
13291330 mapping .append ((length , token ))
13301331 logical .append (text )
1331- length += len (text )
13321332 previous = token
13331333 self .logical_line = '' .join (logical )
13341334 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 ])]
13361336
13371337 def check_logical (self ):
13381338 """Build a line from tokens and run all logical checks on it."""
@@ -1354,10 +1354,10 @@ def check_logical(self):
13541354 (li_number , li_offset ) = offset
13551355 else :
13561356 for (token_offset , token ) in mapping :
1357- if offset < token_offset :
1357+ if offset <= token_offset :
13581358 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 )
13611361 self .report_error (li_number , li_offset , text , check )
13621362 if self .logical_line :
13631363 self .previous_indent_level = self .indent_level
@@ -1460,8 +1460,10 @@ def check_all(self, expected=None, line_offset=0):
14601460 elif COMMENT_WITH_NL and token_type == tokenize .COMMENT :
14611461 if len (self .tokens ) == 1 :
14621462 # 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 )]
14651467 self .check_logical ()
14661468 return self .report .get_file_results ()
14671469
0 commit comments