Skip to content

Commit 9184238

Browse files
committed
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.
1 parent 68cc24f commit 9184238

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

pycodestyle.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,6 +1794,7 @@ def expand_indent(line):
17941794
>>> expand_indent(' \t')
17951795
16
17961796
"""
1797+
line = line.rstrip('\n\r')
17971798
if '\t' not in line:
17981799
return len(line) - len(line.lstrip())
17991800
result = 0

testsuite/E30not.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ def foo(x):
167167
# for no E30x being emitted.
168168
def bar(): pass
169169
def baz(): pass
170+
171+
172+
def main():
173+
pass
170174
#: E704:4:5 E704:5:5
171175
def foo():
172176
# This emits the (ignored-by-default) E704, but here we're testing

0 commit comments

Comments
 (0)