summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntony Lee <anntzer.lee@gmail.com>2020-02-26 00:44:36 +0100
committerAntony Lee <anntzer.lee@gmail.com>2020-02-26 00:56:41 +0100
commit9184238b5668829759babcef61a70b2a6d433162 (patch)
tree7c6dfcc7133e5b533263fe4ab23f38b0db04c92e
parent68cc24fbe60ce31e2f9b40dc6dd484b2abf3a705 (diff)
downloadpep8-9184238b5668829759babcef61a70b2a6d433162.tar.gz
Correctly allow *two* blank lines after a block of one-liners.
Previously ``` def oneliner(): pass def otheroneliner(): pass def really_long_func(): with_some_contents ``` would raise an "E302: expected 2 blank lines, found zero" at the last line of the one liner. Ultimately, this is due to `expand_indent` being passed a line whose contents are just a newline and nothing else, and `expand_indent` thinking that the line is indented by 1 character (the newline), which is wrong. Fix that by just stripping the newline, and modify a test to cover this case.
-rwxr-xr-xpycodestyle.py1
-rw-r--r--testsuite/E30not.py4
2 files changed, 5 insertions, 0 deletions
diff --git a/pycodestyle.py b/pycodestyle.py
index 705ba25..0d0789d 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -1794,6 +1794,7 @@ def expand_indent(line):
>>> expand_indent(' \t')
16
"""
+ line = line.rstrip('\n\r')
if '\t' not in line:
return len(line) - len(line.lstrip())
result = 0
diff --git a/testsuite/E30not.py b/testsuite/E30not.py
index ef795a8..ba0f742 100644
--- a/testsuite/E30not.py
+++ b/testsuite/E30not.py
@@ -167,6 +167,10 @@ def foo(x):
# for no E30x being emitted.
def bar(): pass
def baz(): pass
+
+
+def main():
+ pass
#: E704:4:5 E704:5:5
def foo():
# This emits the (ignored-by-default) E704, but here we're testing