@@ -227,7 +227,7 @@ def maximum_line_length(physical_line, max_line_length, multiline):
227
227
228
228
229
229
def blank_lines (logical_line , blank_lines , indent_level , line_number ,
230
- previous_logical , previous_indent_level ):
230
+ blank_before , previous_logical , previous_indent_level ):
231
231
r"""Separate top-level function and class definitions with two blank lines.
232
232
233
233
Method definitions inside a class are separated by a single blank line.
@@ -256,11 +256,11 @@ def blank_lines(logical_line, blank_lines, indent_level, line_number,
256
256
yield 0 , "E303 too many blank lines (%d)" % blank_lines
257
257
elif logical_line .startswith (('def ' , 'class ' , '@' )):
258
258
if indent_level :
259
- if not (blank_lines or previous_indent_level < indent_level or
259
+ if not (blank_before or previous_indent_level < indent_level or
260
260
DOCSTRING_REGEX .match (previous_logical )):
261
261
yield 0 , "E301 expected 1 blank line, found 0"
262
- elif blank_lines != 2 :
263
- yield 0 , "E302 expected 2 blank lines, found %d" % blank_lines
262
+ elif blank_before != 2 :
263
+ yield 0 , "E302 expected 2 blank lines, found %d" % blank_before
264
264
265
265
266
266
def extraneous_whitespace (logical_line ):
@@ -1339,6 +1339,8 @@ def check_logical(self):
1339
1339
(start_row , start_col ) = mapping [0 ][1 ][2 ]
1340
1340
start_line = self .lines [start_row - 1 ]
1341
1341
self .indent_level = expand_indent (start_line [:start_col ])
1342
+ if self .blank_before < self .blank_lines :
1343
+ self .blank_before = self .blank_lines
1342
1344
if self .verbose >= 2 :
1343
1345
print (self .logical_line [:80 ].rstrip ())
1344
1346
for name , check , argument_names in self ._logical_checks :
@@ -1358,6 +1360,7 @@ def check_logical(self):
1358
1360
if self .logical_line :
1359
1361
self .previous_indent_level = self .indent_level
1360
1362
self .previous_logical = self .logical_line
1363
+ self .blank_lines = 0
1361
1364
self .tokens = []
1362
1365
1363
1366
def check_ast (self ):
@@ -1421,11 +1424,10 @@ def check_all(self, expected=None, line_offset=0):
1421
1424
self .check_ast ()
1422
1425
self .line_number = 0
1423
1426
self .indent_char = None
1424
- self .indent_level = 0
1425
- self .previous_indent_level = 0
1427
+ self .indent_level = self .previous_indent_level = 0
1426
1428
self .previous_logical = ''
1427
1429
self .tokens = []
1428
- self .blank_lines = blank_lines_before_comment = 0
1430
+ self .blank_lines = self . blank_before = 0
1429
1431
parens = 0
1430
1432
for token in self .generate_tokens ():
1431
1433
self .tokens .append (token )
@@ -1444,22 +1446,17 @@ def check_all(self, expected=None, line_offset=0):
1444
1446
parens -= 1
1445
1447
elif not parens :
1446
1448
if token_type == tokenize .NEWLINE :
1447
- if self .blank_lines < blank_lines_before_comment :
1448
- self .blank_lines = blank_lines_before_comment
1449
1449
self .check_logical ()
1450
- self .blank_lines = blank_lines_before_comment = 0
1450
+ self .blank_before = 0
1451
1451
elif token_type == tokenize .NL :
1452
1452
if len (self .tokens ) == 1 :
1453
1453
# The physical line contains only this token.
1454
1454
self .blank_lines += 1
1455
1455
del self .tokens [0 ]
1456
1456
else :
1457
1457
self .check_logical ()
1458
- elif token_type == tokenize .COMMENT and len (self .tokens ) == 1 :
1459
- if blank_lines_before_comment < self .blank_lines :
1460
- blank_lines_before_comment = self .blank_lines
1461
- self .blank_lines = 0
1462
- if COMMENT_WITH_NL :
1458
+ elif COMMENT_WITH_NL and token_type == tokenize .COMMENT :
1459
+ if len (self .tokens ) == 1 :
1463
1460
# The comment also ends a physical line
1464
1461
text = text .rstrip ('\r \n ' )
1465
1462
self .tokens = [(token_type , text ) + token [2 :]]
0 commit comments