From 92a02611d44d4f80e27490ba39123d231f222f7e Mon Sep 17 00:00:00 2001 From: Jonah Lawrence Date: Sat, 22 Oct 2022 21:08:39 -0600 Subject: [PATCH] fix: Ignore pass multiple lines after docstring with flag (#177) * 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 --- autoflake.py | 8 +++++--- test_autoflake.py | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/autoflake.py b/autoflake.py index 674c1c4..c71146a 100755 --- a/autoflake.py +++ b/autoflake.py @@ -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] @@ -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". @@ -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( diff --git a/test_autoflake.py b/test_autoflake.py index 47362de..e53e279 100755 --- a/test_autoflake.py +++ b/test_autoflake.py @@ -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 @@ -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 @@ -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