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 all 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
8 changes: 5 additions & 3 deletions autoflake.py
Expand Up @@ -754,6 +754,7 @@ def useless_pass_line_numbers(
last_pass_row = None
last_pass_indentation = None
previous_line = ""
previous_non_empty_line = ""
for token in tokenize.generate_tokens(sio.readline):
token_type = token[0]
start_row = token[2][0]
Expand All @@ -779,9 +780,8 @@ def useless_pass_line_numbers(
and not previous_line.rstrip().endswith("\\")
)

is_pass_after_docstring = (
previous_token_type == tokenize.NEWLINE
and previous_line.rstrip().endswith('"""')
is_pass_after_docstring = previous_non_empty_line.rstrip().endswith(
("'''", '"""'),
)

# Trailing "pass".
Expand All @@ -793,6 +793,8 @@ def useless_pass_line_numbers(

previous_token_type = token_type
previous_line = line
if line.strip():
previous_non_empty_line = line


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

pass
def foo3():
\"\"\" A docstring. \"\"\"


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

pass
def foo3():
\"\"\" A docstring. \"\"\"


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

pass
def foo3():
\"\"\" A docstring. \"\"\"


pass
def bar():
# abc
Expand Down