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

autoflake should ignore unused variables starting with '_' #96

Open
yoursvivek opened this issue Sep 21, 2021 · 0 comments
Open

autoflake should ignore unused variables starting with '_' #96

yoursvivek opened this issue Sep 21, 2021 · 0 comments

Comments

@yoursvivek
Copy link

autoflake --remove-unused-variables option should not remove variable with names starting with underscore. Or at least they it should give an opt-in feature.

For test file t.py as follows

def fetch_user(value):
    "let's say it returns user or raises Exception when user isn't found"
    return {"pk": 2}

def fetch_settings(value):
    "let's say it returns user settings or raises Exception when settings isn't found"
    return {"pk": 3}

def check_user_regn_complete(value):
    user = fetch_user(value)
    _settings = fetch_settings(value)

Result of running autoflake --remove-unused-variables t.py

--- original/t.py
+++ fixed/t.py
@@ -7,5 +7,5 @@
     return {"pk": 3}
 
 def check_user_regn_complete(value):
-    user = fetch_user(value)
-    _settings = fetch_settings(value)
+    fetch_user(value)
+    fetch_settings(value)

Assignment to variable _settings is a good practice as opposed to not assigning it at all.

Expected result:

--- original/t.py
+++ fixed/t.py
@@ -7,6 +7,6 @@
     return {"pk": 3}
 
 def check_user_regn_complete(value):
-    user = fetch_user(value)
+    fetch_user(value)
     _settings = fetch_settings(value)
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

1 participant