summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lee <IanLee1521@gmail.com>2015-01-07 00:31:24 -0800
committerIan Lee <IanLee1521@gmail.com>2015-01-07 00:31:24 -0800
commit7e16b2b1558305e91bfd5ab2e7f29a3cd4879155 (patch)
treef7d8398d9dfd560a431f20de466effaf0ff3a33d
parentf4a2676edb3d37628db55c857f307416dc4a5bf4 (diff)
downloadpep8-7e16b2b1558305e91bfd5ab2e7f29a3cd4879155.tar.gz
Fix issue #366
Move checking of def / class to higher spot in if statement. This changes some E303 errors into E302 errors, such as for: def a():\n pass\n\n\n\ndef b():\n pass
-rwxr-xr-xpep8.py6
-rw-r--r--testsuite/E30.py9
2 files changed, 12 insertions, 3 deletions
diff --git a/pep8.py b/pep8.py
index 67b32d1..78479bd 100755
--- a/pep8.py
+++ b/pep8.py
@@ -248,7 +248,7 @@ def blank_lines(logical_line, blank_lines, indent_level, line_number,
E301: class Foo:\n b = 0\n def bar():\n pass
E302: def a():\n pass\n\ndef b(n):\n pass
- E303: def a():\n pass\n\n\n\ndef b(n):\n pass
+ E302: def a():\n pass\n\n\n\ndef b(n):\n pass
E303: def a():\n\n\n\n pass
E304: @decorator\n\ndef a():\n pass
"""
@@ -257,8 +257,6 @@ def blank_lines(logical_line, blank_lines, indent_level, line_number,
if previous_logical.startswith('@'):
if blank_lines:
yield 0, "E304 blank lines found after function decorator"
- elif blank_lines > 2 or (indent_level and blank_lines == 2):
- yield 0, "E303 too many blank lines (%d)" % blank_lines
elif logical_line.startswith(('def ', 'class ', '@')):
if indent_level:
if not (blank_before or previous_indent_level < indent_level or
@@ -266,6 +264,8 @@ def blank_lines(logical_line, blank_lines, indent_level, line_number,
yield 0, "E301 expected 1 blank line, found 0"
elif blank_before != 2:
yield 0, "E302 expected 2 blank lines, found %d" % blank_before
+ elif blank_lines > 2 or (indent_level and blank_lines == 2):
+ yield 0, "E303 too many blank lines (%d)" % blank_lines
def extraneous_whitespace(logical_line):
diff --git a/testsuite/E30.py b/testsuite/E30.py
index d2d7bf3..be41a30 100644
--- a/testsuite/E30.py
+++ b/testsuite/E30.py
@@ -87,4 +87,13 @@ def function():
"""This class docstring comes on line 5.
It gives error E303: too many blank lines (3)
"""
+#: E302
+def a():
+ pass
+
+
+
+
+def b(n):
+ pass
#: