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

remove-unused-variable not removing captured variable in except clauses #66

Open
brupelo opened this issue Apr 15, 2020 · 2 comments
Open

Comments

@brupelo
Copy link

brupelo commented Apr 15, 2020

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
@alvindera97
Copy link

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.

@edvardm
Copy link
Contributor

edvardm commented May 17, 2021

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.

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

No branches or pull requests

4 participants