autoflake
autoflake copied to clipboard
Incorrect replacement of unused variable with pass when followed by comment or empty line
When replacing an unused variable, autoflake
is messed up by seeing an empty line or a comment, and considers that it's an empty function. This results in replacing the unused variable with pass
.
Minimal Reproductible Example
1. With comment
cat << EOF > test.py | autoflake --remove-unused-variables test.py
def main():
unused_variable = 2020
# Harmless comment
print('Harmless print')
EOF
--- original/test_file.py
+++ fixed/test_file.py
@@ -1,4 +1,4 @@
def main():
- unused_variable = 2020
+ pass
# Harmless comment
print('Harmless print')
2. With empty line
cat << EOF > test.py | autoflake --remove-unused-variables test.py
def main():
unused_variable = 2020
print('Harmless print')
EOF
--- original/test.py
+++ fixed/test.py
@@ -1,4 +1,4 @@
def main():
- unused_variable = 2020
+ pass
print('Harmless print')
I can confirm that this issue is still there. Also for imports:
def some_function(self, args):
from tensorflow import reduce_logsumexp
result = args[0]
--- original/test.py
+++ fixed/test.py
@@ -53,7 +53,7
def some_function(self, args):
- from tensorflow import reduce_logsumexp
+ pass
result = args[0]
In my case, this behavior only happens when I pass the --ignore-pass-statements
flag.
Right to the above comment, in which in my case, I want to pass the flag so I can keep the pass
statements for abstract base classes. Great if this could be fixed
I'm seeing this behavior as well when using the --ignore-pass-statements
flag
I am also seeing this behavior when I use the --ignore-pass-statements
flag. Is there a plan to fix this?