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

Incorrect replacement of unused variable with pass when followed by comment or empty line #82

Open
rcstanciu opened this issue Dec 11, 2020 · 5 comments

Comments

@rcstanciu
Copy link

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')
@jneeven
Copy link

jneeven commented Sep 27, 2022

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]

@p-enel
Copy link

p-enel commented Nov 18, 2022

In my case, this behavior only happens when I pass the --ignore-pass-statements flag.

@chantel-marie-diaz
Copy link

chantel-marie-diaz commented Nov 18, 2022

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

@noam-better
Copy link

I'm seeing this behavior as well when using the --ignore-pass-statements flag

@joeyagreco
Copy link

I am also seeing this behavior when I use the --ignore-pass-statements flag. Is there a plan to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants