@@ -227,7 +227,7 @@ def maximum_line_length(physical_line, max_line_length, multiline):
227227
228228
229229def blank_lines (logical_line , blank_lines , indent_level , line_number ,
230- previous_logical , previous_indent_level ):
230+ blank_before , previous_logical , previous_indent_level ):
231231 r"""Separate top-level function and class definitions with two blank lines.
232232
233233 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,
256256 yield 0 , "E303 too many blank lines (%d)" % blank_lines
257257 elif logical_line .startswith (('def ' , 'class ' , '@' )):
258258 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
260260 DOCSTRING_REGEX .match (previous_logical )):
261261 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
264264
265265
266266def extraneous_whitespace (logical_line ):
@@ -1339,6 +1339,8 @@ def check_logical(self):
13391339 (start_row , start_col ) = mapping [0 ][1 ][2 ]
13401340 start_line = self .lines [start_row - 1 ]
13411341 self .indent_level = expand_indent (start_line [:start_col ])
1342+ if self .blank_before < self .blank_lines :
1343+ self .blank_before = self .blank_lines
13421344 if self .verbose >= 2 :
13431345 print (self .logical_line [:80 ].rstrip ())
13441346 for name , check , argument_names in self ._logical_checks :
@@ -1358,6 +1360,7 @@ def check_logical(self):
13581360 if self .logical_line :
13591361 self .previous_indent_level = self .indent_level
13601362 self .previous_logical = self .logical_line
1363+ self .blank_lines = 0
13611364 self .tokens = []
13621365
13631366 def check_ast (self ):
@@ -1421,11 +1424,10 @@ def check_all(self, expected=None, line_offset=0):
14211424 self .check_ast ()
14221425 self .line_number = 0
14231426 self .indent_char = None
1424- self .indent_level = 0
1425- self .previous_indent_level = 0
1427+ self .indent_level = self .previous_indent_level = 0
14261428 self .previous_logical = ''
14271429 self .tokens = []
1428- self .blank_lines = blank_lines_before_comment = 0
1430+ self .blank_lines = self . blank_before = 0
14291431 parens = 0
14301432 for token in self .generate_tokens ():
14311433 self .tokens .append (token )
@@ -1444,22 +1446,17 @@ def check_all(self, expected=None, line_offset=0):
14441446 parens -= 1
14451447 elif not parens :
14461448 if token_type == tokenize .NEWLINE :
1447- if self .blank_lines < blank_lines_before_comment :
1448- self .blank_lines = blank_lines_before_comment
14491449 self .check_logical ()
1450- self .blank_lines = blank_lines_before_comment = 0
1450+ self .blank_before = 0
14511451 elif token_type == tokenize .NL :
14521452 if len (self .tokens ) == 1 :
14531453 # The physical line contains only this token.
14541454 self .blank_lines += 1
14551455 del self .tokens [0 ]
14561456 else :
14571457 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 :
14631460 # The comment also ends a physical line
14641461 text = text .rstrip ('\r \n ' )
14651462 self .tokens = [(token_type , text ) + token [2 :]]
0 commit comments