summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Stapleton Cordasco <graffatcolmingov@gmail.com>2019-01-23 08:01:17 -0600
committerGitHub <noreply@github.com>2019-01-23 08:01:17 -0600
commitdb80d0750951e4a9d1ac82338285496534d6c061 (patch)
treeebc8e326e59158972451fff4d316127bd5d9e73d
parent8940d64045d908d5be84ba60e6eb7846e21adb7a (diff)
parent0138bb106403241564a0c5af67886c05a2f4f690 (diff)
downloadpep8-db80d0750951e4a9d1ac82338285496534d6c061.tar.gz
Merge pull request #823 from anntzer/allow-no-blanks-around-one-liners
Allow omitting blank lines around one-liner definitions.
-rwxr-xr-xpycodestyle.py10
-rw-r--r--testsuite/E30.py18
-rw-r--r--testsuite/E30not.py11
3 files changed, 39 insertions, 0 deletions
diff --git a/pycodestyle.py b/pycodestyle.py
index 9fc1874..094e24f 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -357,6 +357,16 @@ 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.
+ 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
+ expand_indent(next_line) <= indent_level):
+ return
if indent_level:
if not (blank_before == method_lines or
previous_indent_level < indent_level or
diff --git a/testsuite/E30.py b/testsuite/E30.py
index ad5518b..320b2a1 100644
--- a/testsuite/E30.py
+++ b/testsuite/E30.py
@@ -163,3 +163,21 @@ async def x():
async def x(y: int = 1):
pass
+#: E704:3:1 E302:3:1
+def bar():
+ pass
+def baz(): pass
+#: E704:1:1 E302:2:1
+def bar(): pass
+def baz():
+ pass
+#: E704:4:5 E306:4:5
+def foo():
+ def bar():
+ pass
+ def baz(): pass
+#: E704:2:5 E306:3:5
+def foo():
+ def bar(): pass
+ def baz():
+ pass
diff --git a/testsuite/E30not.py b/testsuite/E30not.py
index 6303b3b..ef795a8 100644
--- a/testsuite/E30not.py
+++ b/testsuite/E30not.py
@@ -162,3 +162,14 @@ defaults.update({})
def foo(x):
classification = x
definitely = not classification
+#: E704:3:1 E704:4:1
+# This emits the (ignored-by-default) E704, but here we're testing
+# for no E30x being emitted.
+def bar(): pass
+def baz(): pass
+#: E704:4:5 E704:5:5
+def foo():
+ # This emits the (ignored-by-default) E704, but here we're testing
+ # for no E30x being emitted.
+ def bar(): pass
+ def baz(): pass