@@ -1299,39 +1299,33 @@ def check_physical(self, line):
12991299
13001300 def build_tokens_line (self ):
13011301 """Build a logical line from tokens."""
1302- mapping = []
13031302 logical = []
13041303 comments = []
13051304 length = 0
1306- previous = None
1307- for token in self .tokens :
1308- (token_type , text ) = token [0 :2 ]
1305+ prev_row = prev_col = mapping = None
1306+ for token_type , text , start , end , line in self .tokens :
13091307 if token_type in SKIP_TOKENS :
13101308 continue
13111309 if not mapping :
1312- mapping . append (( 0 , token [ 2 ]))
1310+ mapping = [( 0 , start )]
13131311 if token_type == tokenize .COMMENT :
13141312 comments .append (text )
13151313 continue
13161314 if token_type == tokenize .STRING :
13171315 text = mute_string (text )
1318- if previous :
1319- (end_row , end ) = previous [3 ]
1320- (start_row , start ) = token [2 ]
1321- if end_row != start_row : # different row
1322- prev_text = self .lines [end_row - 1 ][end - 1 ]
1316+ if prev_row :
1317+ (start_row , start_col ) = start
1318+ if prev_row != start_row : # different row
1319+ prev_text = self .lines [prev_row - 1 ][prev_col - 1 ]
13231320 if prev_text == ',' or (prev_text not in '{[('
13241321 and text not in '}])' ):
1325- logical .append (' ' )
1326- length += 1
1327- elif end != start : # different column
1328- fill = self .lines [end_row - 1 ][end :start ]
1329- logical .append (fill )
1330- length += len (fill )
1331- length += len (text )
1332- mapping .append ((length , token [3 ]))
1322+ text = ' ' + text
1323+ elif prev_col != start_col : # different column
1324+ text = line [prev_col :start_col ] + text
13331325 logical .append (text )
1334- previous = token
1326+ length += len (text )
1327+ mapping .append ((length , end ))
1328+ (prev_row , prev_col ) = end
13351329 self .logical_line = '' .join (logical )
13361330 self .noqa = comments and noqa ('' .join (comments ))
13371331 return mapping
0 commit comments