summaryrefslogtreecommitdiff
path: root/pycodestyle.py
diff options
context:
space:
mode:
authorAntony Lee <anntzer.lee@gmail.com>2018-11-28 00:43:17 +0100
committerAntony Lee <anntzer.lee@gmail.com>2019-01-05 17:19:45 +0100
commit0138bb106403241564a0c5af67886c05a2f4f690 (patch)
treea731940febd5e2e925b99f85f8536380fe6a5259 /pycodestyle.py
parent3d37ea0aa2e369852c98bbbcaef8a89ed00996dc (diff)
downloadpep8-0138bb106403241564a0c5af67886c05a2f4f690.tar.gz
Allow omitting blank lines around one-liner definitions.
Diffstat (limited to 'pycodestyle.py')
-rwxr-xr-xpycodestyle.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/pycodestyle.py b/pycodestyle.py
index c9e1667..27009c6 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -354,6 +354,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