autoflake
autoflake copied to clipboard
remove-unused-variable not removing captured variable in except clauses
Requirements
Version: 1.3.1
OS: win7
python: Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (Intel)] on win32
Problem
Running autoflake --remove-all-unused-imports --remove-unused-variables --ignore-init-module-imports --in-place foo.py
with below code:
def foo():
try:
0 / 0
except Exception as e:
pass
Will produce:
def foo():
try:
0 / 0
except Exception as e:
pass
Expected output
def foo():
try:
0 / 0
except Exception:
pass
I agree with this... The --remove-unused-variable flag is very very buggy. In the most obvious of situations, it fails to operate as expected. The --verbose flag in cases like these is a complete waste of time.... Absolutely no output is shown. The command just executes with no data back returned to the user with or without -i flag used.
I would argue it's not very buggy, there are often false reports like this:
# foo.py
a = 1
def hello():
print("howdy")
Should a
be removed? No. It's a global variable, meaning that some user of that code could be using foo.a
to access that.
However, unused exception var is removed for me exactly as it should, using autoflake 1.4, python 3.8.7
. I'd close this issue.