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

Removing unused variables doesn't work #87

Open
aprilahijriyan opened this issue Mar 5, 2021 · 1 comment
Open

Removing unused variables doesn't work #87

aprilahijriyan opened this issue Mar 5, 2021 · 1 comment

Comments

@aprilahijriyan
Copy link

I have a sample bad_code.py script below:

import os  # unused import
import abc

unused_var = 1
print("hello world")

And I run it with the command:

autoflake --in-place --remove-unused-variables --remove-all-unused-imports bad_code.py

However, the unused_var variable is not deleted :/

@edvardm
Copy link
Contributor

edvardm commented May 7, 2021

I would say it makes sense it isn't removed, as unused_var has global scope here.

If that code was in a library foo, then unused_var could be accessed with foo.unused_var which might be part of it's api, hence not safe to remove.

If you had

import os  # unused import
import abc

def fun():
    unused_var = 1
    print("hello world")

then it would be removed, as it's a local variable (which could not be accessed outside fun)

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

2 participants