Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ignore pass multiple lines after docstring with flag #177

Merged
merged 5 commits into from Oct 23, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions autoflake.py
Expand Up @@ -753,7 +753,7 @@ def useless_pass_line_numbers(
previous_token_type = None
last_pass_row = None
last_pass_indentation = None
previous_line = ""
previous_lines = collections.deque(("", ""), maxlen=2)
for token in tokenize.generate_tokens(sio.readline):
token_type = token[0]
start_row = token[2][0]
Expand All @@ -776,12 +776,18 @@ def useless_pass_line_numbers(

is_trailing_pass = (
previous_token_type != tokenize.INDENT
and not previous_line.rstrip().endswith("\\")
and not previous_lines[-1].rstrip().endswith("\\")
)

is_pass_after_docstring = (
# previous line is the end of a docstring
previous_token_type == tokenize.NEWLINE
and previous_line.rstrip().endswith('"""')
and previous_lines[-1].rstrip().endswith(("'''", '"""'))
) or (
# previous line contains only space and the line before that is
# the end of a docstring
previous_lines[-1].strip() == ""
and previous_lines[-2].rstrip().endswith(("'''", '"""'))
)

# Trailing "pass".
Expand All @@ -792,7 +798,7 @@ def useless_pass_line_numbers(
yield start_row

previous_token_type = token_type
previous_line = line
previous_lines.append(line)


def filter_useless_pass(
Expand Down
12 changes: 12 additions & 0 deletions test_autoflake.py
Expand Up @@ -1418,6 +1418,10 @@ def test_fix_code_keeps_pass_statements(self):
else:
def foo():
\"\"\" A docstring. \"\"\"
pass
def foo2():
\"\"\" A docstring. \"\"\"

pass
def bar():
# abc
Expand Down Expand Up @@ -1447,6 +1451,10 @@ def test_fix_code_keeps_passes_after_docstrings(self):
else:
def foo():
\"\"\" A docstring. \"\"\"
pass
def foo2():
\"\"\" A docstring. \"\"\"

pass
def bar():
# abc
Expand All @@ -1466,6 +1474,10 @@ def blah():
else:
def foo():
\"\"\" A docstring. \"\"\"
pass
def foo2():
\"\"\" A docstring. \"\"\"

pass
def bar():
# abc
Expand Down