From 7493e0a0e76f02640b6ff0f7cb1619747101a1c6 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 26 Mar 2019 18:01:22 +0100 Subject: Fix E302 false negative in presence of decorators. --- pycodestyle.py | 13 +++++++------ testsuite/E30.py | 8 ++++++++ 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 -- cgit v1.2.1