summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Stapleton Cordasco <graffatcolmingov@gmail.com>2019-03-26 12:31:47 -0500
committerGitHub <noreply@github.com>2019-03-26 12:31:47 -0500
commit3b258c375c6392b1475a487c0961cf7dbe03f838 (patch)
tree1ca932d1a19351b76f4275f111dcafc1b14fc4f2
parent96d2db0fa17cc41ae45bcc6fa5ca72e6f712d1bf (diff)
parent7493e0a0e76f02640b6ff0f7cb1619747101a1c6 (diff)
downloadpep8-3b258c375c6392b1475a487c0961cf7dbe03f838.tar.gz
Merge pull request #859 from anntzer/e302decorator
Fix E302 false negative in presence of decorators.
-rwxr-xr-xpycodestyle.py13
-rw-r--r--testsuite/E30.py8
2 files changed, 15 insertions, 6 deletions
diff --git a/pycodestyle.py b/pycodestyle.py
index 03696b7..ec6b894 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -358,14 +358,15 @@ def blank_lines(logical_line, blank_lines, indent_level, line_number,
):
yield 0, "E303 too many blank lines (%d)" % blank_lines
elif STARTSWITH_TOP_LEVEL_REGEX.match(logical_line):
- # If this is a one-liner (i.e. the next line is not more
- # indented), and the previous line is also not deeper
- # (it would be better to check if the previous line is part
- # of another def/class at the same level), don't require blank
- # lines around this.
+ # If this is a one-liner (i.e. this is not a decorator and the
+ # next line is not more indented), and the previous line is also
+ # not deeper (it would be better to check if the previous line
+ # is part of another def/class at the same level), don't require
+ # blank lines around this.
prev_line = lines[line_number - 2] if line_number >= 2 else ''
next_line = lines[line_number] if line_number < len(lines) else ''
- if (expand_indent(prev_line) <= indent_level and
+ if (not logical_line.startswith("@") and
+ expand_indent(prev_line) <= indent_level and
expand_indent(next_line) <= indent_level):
return
if indent_level:
diff --git a/testsuite/E30.py b/testsuite/E30.py
index 320b2a1..15fbdf3 100644
--- a/testsuite/E30.py
+++ b/testsuite/E30.py
@@ -181,3 +181,11 @@ def foo():
def bar(): pass
def baz():
pass
+#: E302:5:1
+def f():
+ pass
+
+# wat
+@hi
+def g():
+ pass