88
88
'**=' , '*=' , '/=' , '//=' , '+=' , '-=' , '!=' , '<>' , '<' , '>' ,
89
89
'%=' , '^=' , '&=' , '|=' , '==' , '<=' , '>=' , '<<=' , '>>=' , '=' ])
90
90
WHITESPACE = frozenset (' \t ' )
91
- SKIP_TOKENS = frozenset ([tokenize .COMMENT , tokenize . NL , tokenize .NEWLINE ,
91
+ SKIP_TOKENS = frozenset ([tokenize .NL , tokenize .NEWLINE ,
92
92
tokenize .INDENT , tokenize .DEDENT ])
93
93
BENCHMARK_KEYS = ['directories' , 'files' , 'logical lines' , 'physical lines' ]
94
94
@@ -1306,11 +1306,13 @@ def build_tokens_line(self):
1306
1306
previous = None
1307
1307
for token in self .tokens :
1308
1308
(token_type , text ) = token [0 :2 ]
1309
+ if token_type in SKIP_TOKENS :
1310
+ continue
1311
+ if not mapping :
1312
+ mapping .append ((0 , token [2 ]))
1309
1313
if token_type == tokenize .COMMENT :
1310
1314
comments .append (text )
1311
1315
continue
1312
- if token_type in SKIP_TOKENS :
1313
- continue
1314
1316
if token_type == tokenize .STRING :
1315
1317
text = mute_string (text )
1316
1318
if previous :
@@ -1327,18 +1329,18 @@ def build_tokens_line(self):
1327
1329
logical .append (fill )
1328
1330
length += len (fill )
1329
1331
length += len (text )
1330
- mapping .append ((length , token ))
1332
+ mapping .append ((length , token [ 3 ] ))
1331
1333
logical .append (text )
1332
1334
previous = token
1333
1335
self .logical_line = '' .join (logical )
1334
1336
self .noqa = comments and noqa ('' .join (comments ))
1335
- return mapping or [( len ( self . tokens [ 0 ][ 1 ]), self . tokens [ 0 ])]
1337
+ return mapping
1336
1338
1337
1339
def check_logical (self ):
1338
1340
"""Build a line from tokens and run all logical checks on it."""
1339
1341
self .report .increment_logical_line ()
1340
1342
mapping = self .build_tokens_line ()
1341
- (start_row , start_col ) = mapping [0 ][1 ][ 2 ]
1343
+ (start_row , start_col ) = mapping [0 ][1 ]
1342
1344
start_line = self .lines [start_row - 1 ]
1343
1345
self .indent_level = expand_indent (start_line [:start_col ])
1344
1346
if self .blank_before < self .blank_lines :
@@ -1350,10 +1352,10 @@ def check_logical(self):
1350
1352
print (' ' + name )
1351
1353
for offset , text in self .run_check (check , argument_names ) or ():
1352
1354
if not isinstance (offset , tuple ):
1353
- for token_offset , token in mapping :
1355
+ for token_offset , pos in mapping :
1354
1356
if offset <= token_offset :
1355
1357
break
1356
- offset = (token [ 3 ][ 0 ], token [ 3 ] [1 ] + offset - token_offset )
1358
+ offset = (pos [ 0 ], pos [1 ] + offset - token_offset )
1357
1359
self .report_error (offset [0 ], offset [1 ], text , check )
1358
1360
if self .logical_line :
1359
1361
self .previous_indent_level = self .indent_level
0 commit comments