Skip to content

Commit 3b258c3

Browse files
authored
Merge pull request #859 from anntzer/e302decorator
Fix E302 false negative in presence of decorators.
2 parents 96d2db0 + 7493e0a commit 3b258c3

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

pycodestyle.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,14 +358,15 @@ def blank_lines(logical_line, blank_lines, indent_level, line_number,
358358
):
359359
yield 0, "E303 too many blank lines (%d)" % blank_lines
360360
elif STARTSWITH_TOP_LEVEL_REGEX.match(logical_line):
361-
# If this is a one-liner (i.e. the next line is not more
362-
# indented), and the previous line is also not deeper
363-
# (it would be better to check if the previous line is part
364-
# of another def/class at the same level), don't require blank
365-
# lines around this.
361+
# If this is a one-liner (i.e. this is not a decorator and the
362+
# next line is not more indented), and the previous line is also
363+
# not deeper (it would be better to check if the previous line
364+
# is part of another def/class at the same level), don't require
365+
# blank lines around this.
366366
prev_line = lines[line_number - 2] if line_number >= 2 else ''
367367
next_line = lines[line_number] if line_number < len(lines) else ''
368-
if (expand_indent(prev_line) <= indent_level and
368+
if (not logical_line.startswith("@") and
369+
expand_indent(prev_line) <= indent_level and
369370
expand_indent(next_line) <= indent_level):
370371
return
371372
if indent_level:

testsuite/E30.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,11 @@ def foo():
181181
def bar(): pass
182182
def baz():
183183
pass
184+
#: E302:5:1
185+
def f():
186+
pass
187+
188+
# wat
189+
@hi
190+
def g():
191+
pass

0 commit comments

Comments
 (0)