8888 '**=' , '*=' , '/=' , '//=' , '+=' , '-=' , '!=' , '<>' , '<' , '>' ,
8989 '%=' , '^=' , '&=' , '|=' , '==' , '<=' , '>=' , '<<=' , '>>=' , '=' ])
9090WHITESPACE = frozenset (' \t ' )
91- SKIP_TOKENS = frozenset ([tokenize .COMMENT , tokenize . NL , tokenize .NEWLINE ,
91+ SKIP_TOKENS = frozenset ([tokenize .NL , tokenize .NEWLINE ,
9292 tokenize .INDENT , tokenize .DEDENT ])
9393BENCHMARK_KEYS = ['directories' , 'files' , 'logical lines' , 'physical lines' ]
9494
@@ -1306,11 +1306,13 @@ def build_tokens_line(self):
13061306 previous = None
13071307 for token in self .tokens :
13081308 (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 ]))
13091313 if token_type == tokenize .COMMENT :
13101314 comments .append (text )
13111315 continue
1312- if token_type in SKIP_TOKENS :
1313- continue
13141316 if token_type == tokenize .STRING :
13151317 text = mute_string (text )
13161318 if previous :
@@ -1327,18 +1329,18 @@ def build_tokens_line(self):
13271329 logical .append (fill )
13281330 length += len (fill )
13291331 length += len (text )
1330- mapping .append ((length , token ))
1332+ mapping .append ((length , token [ 3 ] ))
13311333 logical .append (text )
13321334 previous = token
13331335 self .logical_line = '' .join (logical )
13341336 self .noqa = comments and noqa ('' .join (comments ))
1335- return mapping or [( len ( self . tokens [ 0 ][ 1 ]), self . tokens [ 0 ])]
1337+ return mapping
13361338
13371339 def check_logical (self ):
13381340 """Build a line from tokens and run all logical checks on it."""
13391341 self .report .increment_logical_line ()
13401342 mapping = self .build_tokens_line ()
1341- (start_row , start_col ) = mapping [0 ][1 ][ 2 ]
1343+ (start_row , start_col ) = mapping [0 ][1 ]
13421344 start_line = self .lines [start_row - 1 ]
13431345 self .indent_level = expand_indent (start_line [:start_col ])
13441346 if self .blank_before < self .blank_lines :
@@ -1350,10 +1352,10 @@ def check_logical(self):
13501352 print (' ' + name )
13511353 for offset , text in self .run_check (check , argument_names ) or ():
13521354 if not isinstance (offset , tuple ):
1353- for token_offset , token in mapping :
1355+ for token_offset , pos in mapping :
13541356 if offset <= token_offset :
13551357 break
1356- offset = (token [ 3 ][ 0 ], token [ 3 ] [1 ] + offset - token_offset )
1358+ offset = (pos [ 0 ], pos [1 ] + offset - token_offset )
13571359 self .report_error (offset [0 ], offset [1 ], text , check )
13581360 if self .logical_line :
13591361 self .previous_indent_level = self .indent_level
0 commit comments