@@ -1299,39 +1299,33 @@ def check_physical(self, line):
1299
1299
1300
1300
def build_tokens_line (self ):
1301
1301
"""Build a logical line from tokens."""
1302
- mapping = []
1303
1302
logical = []
1304
1303
comments = []
1305
1304
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 :
1309
1307
if token_type in SKIP_TOKENS :
1310
1308
continue
1311
1309
if not mapping :
1312
- mapping . append (( 0 , token [ 2 ]))
1310
+ mapping = [( 0 , start )]
1313
1311
if token_type == tokenize .COMMENT :
1314
1312
comments .append (text )
1315
1313
continue
1316
1314
if token_type == tokenize .STRING :
1317
1315
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 ]
1323
1320
if prev_text == ',' or (prev_text not in '{[('
1324
1321
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
1333
1325
logical .append (text )
1334
- previous = token
1326
+ length += len (text )
1327
+ mapping .append ((length , end ))
1328
+ (prev_row , prev_col ) = end
1335
1329
self .logical_line = '' .join (logical )
1336
1330
self .noqa = comments and noqa ('' .join (comments ))
1337
1331
return mapping
0 commit comments