summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2020-03-24 14:44:31 -0700
committerGitHub <noreply@github.com>2020-03-24 14:44:31 -0700
commita9e8ebcf821b99c7587cc0b566396fc3f1c9d81b (patch)
tree0215793a881dc536d23501b10e9bc0a41e6a8182
parent19a3925a89c71d422b98363d9ccfa8903a65b707 (diff)
parent7e3655b9655ed8a13daa65c6cd2f38a06bfa5469 (diff)
downloadpep8-a9e8ebcf821b99c7587cc0b566396fc3f1c9d81b.tar.gz
Merge pull request #919 from asottile/first_line_E302
Allow N-and-fewer blank lines before the first top level thing
-rwxr-xr-xpycodestyle.py2
-rw-r--r--testsuite/E30.py5
-rw-r--r--testsuite/E30not.py10
-rw-r--r--testsuite/test_blank_lines.py4
4 files changed, 12 insertions, 9 deletions
diff --git a/pycodestyle.py b/pycodestyle.py
index 235532c..d2e9337 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -350,7 +350,7 @@ def blank_lines(logical_line, blank_lines, indent_level, line_number,
top_level_lines = BLANK_LINES_CONFIG['top_level']
method_lines = BLANK_LINES_CONFIG['method']
- if line_number < top_level_lines + 1 and not previous_logical:
+ if not previous_logical and blank_before < top_level_lines:
return # Don't expect blank lines before the first line
if previous_logical.startswith('@'):
if blank_lines:
diff --git a/testsuite/E30.py b/testsuite/E30.py
index 15fbdf3..8d1879b 100644
--- a/testsuite/E30.py
+++ b/testsuite/E30.py
@@ -16,11 +16,6 @@ class X:
#:
-#: E302:3:1
-#!python
-# -*- coding: utf-8 -*-
-def a():
- pass
#: E302:2:1
"""Main module."""
def _main():
diff --git a/testsuite/E30not.py b/testsuite/E30not.py
index ba0f742..a86b99e 100644
--- a/testsuite/E30not.py
+++ b/testsuite/E30not.py
@@ -177,3 +177,13 @@ def foo():
# for no E30x being emitted.
def bar(): pass
def baz(): pass
+#: Okay
+#!python
+# -*- coding: utf-8 -*-
+def a():
+ pass
+#: Okay
+def f(
+ a,
+):
+ pass
diff --git a/testsuite/test_blank_lines.py b/testsuite/test_blank_lines.py
index 2b37ad1..e239f8b 100644
--- a/testsuite/test_blank_lines.py
+++ b/testsuite/test_blank_lines.py
@@ -139,7 +139,6 @@ class AFarEnoughClass(object):
pass
""")
self.assertEqual([
- 'E302:4:1', # some_function
'E302:7:1', # another_function
'E302:14:1', # SomeCloseClass
], result)
@@ -438,7 +437,7 @@ def some_function():
def test_top_level_fewer_blank_lines(self):
"""
- It will trigger an error when less 2 blank lines are found
+ It will trigger an error when less 3 blank lines are found
before top level definitions.
"""
result = self.check("""# First comment line.
@@ -471,7 +470,6 @@ class AFarEnoughClass(object):
pass
""")
self.assertEqual([
- 'E302:5:1', # some_function
'E302:9:1', # another_function
'E302:17:1', # SomeCloseClass
], result)