Skip to content

Commit a9e8ebc

Browse files
authored
Merge pull request #919 from asottile/first_line_E302
Allow N-and-fewer blank lines before the first top level thing
2 parents 19a3925 + 7e3655b commit a9e8ebc

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

pycodestyle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def blank_lines(logical_line, blank_lines, indent_level, line_number,
350350
top_level_lines = BLANK_LINES_CONFIG['top_level']
351351
method_lines = BLANK_LINES_CONFIG['method']
352352

353-
if line_number < top_level_lines + 1 and not previous_logical:
353+
if not previous_logical and blank_before < top_level_lines:
354354
return # Don't expect blank lines before the first line
355355
if previous_logical.startswith('@'):
356356
if blank_lines:

testsuite/E30.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ def b():
1616
#:
1717

1818

19-
#: E302:3:1
20-
#!python
21-
# -*- coding: utf-8 -*-
22-
def a():
23-
pass
2419
#: E302:2:1
2520
"""Main module."""
2621
def _main():

testsuite/E30not.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,13 @@ def foo():
177177
# for no E30x being emitted.
178178
def bar(): pass
179179
def baz(): pass
180+
#: Okay
181+
#!python
182+
# -*- coding: utf-8 -*-
183+
def a():
184+
pass
185+
#: Okay
186+
def f(
187+
a,
188+
):
189+
pass

testsuite/test_blank_lines.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ class AFarEnoughClass(object):
139139
pass
140140
""")
141141
self.assertEqual([
142-
'E302:4:1', # some_function
143142
'E302:7:1', # another_function
144143
'E302:14:1', # SomeCloseClass
145144
], result)
@@ -438,7 +437,7 @@ def some_function():
438437

439438
def test_top_level_fewer_blank_lines(self):
440439
"""
441-
It will trigger an error when less 2 blank lines are found
440+
It will trigger an error when less 3 blank lines are found
442441
before top level definitions.
443442
"""
444443
result = self.check("""# First comment line.
@@ -471,7 +470,6 @@ class AFarEnoughClass(object):
471470
pass
472471
""")
473472
self.assertEqual([
474-
'E302:5:1', # some_function
475473
'E302:9:1', # another_function
476474
'E302:17:1', # SomeCloseClass
477475
], result)

0 commit comments

Comments
 (0)