@@ -1296,7 +1296,7 @@ def check_physical(self, line):
1296
1296
1297
1297
def build_tokens_line (self ):
1298
1298
"""Build a logical line from tokens."""
1299
- self . mapping = []
1299
+ mapping = []
1300
1300
logical = []
1301
1301
comments = []
1302
1302
length = 0
@@ -1323,23 +1323,21 @@ def build_tokens_line(self):
1323
1323
fill = self .lines [end_row - 1 ][end :start ]
1324
1324
logical .append (fill )
1325
1325
length += len (fill )
1326
- self . mapping .append ((length , token ))
1326
+ mapping .append ((length , token ))
1327
1327
logical .append (text )
1328
1328
length += len (text )
1329
1329
previous = token
1330
1330
self .logical_line = '' .join (logical )
1331
1331
self .noqa = comments and noqa ('' .join (comments ))
1332
- # With Python 2, if the line ends with '\r\r\n' the assertion fails
1333
- # assert self.logical_line.strip() == self.logical_line
1332
+ return mapping or [(0 , self .tokens [0 ])]
1334
1333
1335
1334
def check_logical (self ):
1336
1335
"""Build a line from tokens and run all logical checks on it."""
1337
- self .build_tokens_line ()
1338
1336
self .report .increment_logical_line ()
1339
- token0 = self .mapping [ 0 ][ 1 ] if self . mapping else self . tokens [ 0 ]
1340
- first_line = self . lines [ token0 [ 2 ][ 0 ] - 1 ]
1341
- indent = first_line [: token0 [ 2 ][ 1 ] ]
1342
- self .indent_level = expand_indent (indent )
1337
+ mapping = self .build_tokens_line ()
1338
+ ( start_row , start_col ) = mapping [ 0 ][ 1 ][ 2 ]
1339
+ start_line = self . lines [ start_row - 1 ]
1340
+ self .indent_level = expand_indent (start_line [: start_col ] )
1343
1341
if self .verbose >= 2 :
1344
1342
print (self .logical_line [:80 ].rstrip ())
1345
1343
for name , check , argument_names in self ._logical_checks :
@@ -1350,8 +1348,7 @@ def check_logical(self):
1350
1348
if isinstance (offset , tuple ):
1351
1349
(li_number , li_offset ) = offset
1352
1350
else :
1353
- (token_offset , token ) = (0 , token0 )
1354
- for (token_offset , token ) in self .mapping :
1351
+ for (token_offset , token ) in mapping :
1355
1352
if offset < token_offset :
1356
1353
break
1357
1354
li_number = token [2 ][0 ]
0 commit comments