Skip to content

Commit

Permalink
fix: Ignore pass multiple lines after docstring with flag (#177)
Browse files Browse the repository at this point in the history
* fix: Ignore pass two lines after docstring with flag

* Update test_autoflake.py

* Use -2, -1 instead of 0, 1 for readability

* feat: support for any number of empty lines

* style: pre-commit run
  • Loading branch information
DenverCoder1 committed Oct 23, 2022
1 parent 3d9a7ab commit 92a0261
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
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

0 comments on commit 92a0261

Please sign in to comment.