-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
False negative unused-variable
for catched exception when used in the inner context
#4391
Comments
Hello, I think that pylint considers the
Output:
|
Good point, this is certainely part of it, but I think that without the
|
Without the |
I assigned you :) Thanks for handling this ! |
Thank you:) One question, are there separate test files for the |
Separate test files ? I don't know if I understood but there is some functional tests here: https://github.com/PyCQA/pylint/tree/master/tests/functional/u/unused |
okay great thanks |
Now that I am looking at it a bit better, I notice that the same exception has been named as |
The second
|
In the |
Yes the error would be used in the print then so no error should appear if there is a print. I think flake8 has a check for unused variable that works for this use case. |
This fix is high effort as it require to modify control flow in astroid, please refer to this if you want to tackle it :) |
Should probably be handled the same way as #5630 with a LIFO queue. |
@Pierre-Sassoulas I guess this can be closed now :) |
We currently do: ❯ cat test.py
# pylint: disable=missing-docstring
def function():
unused = 1 # [unused-variable]
try:
1 / 0
except ZeroDivisionError as error: # [unused-variable]
try:
1 / 0
except ZeroDivisionError as error:
raise Exception("") from error
❯ pylint test.py
************* Module _binding.test
test.py:11:8: W0621: Redefining name 'error' from outer scope (line 8) (redefined-outer-name)
test.py:5:4: W0612: Unused variable 'unused' (unused-variable)
------------------------------------------------------------------
Your code has been rated at 7.78/10 (previous run: 7.78/10, +0.00) Is this the desired behaviour? |
Thank you for testing this @DanielNoord , I think one of the unused variable is still a false negative (the first level |
I think the output Daniel shows is correct -- line 8 overwrites "error" from line 5, so in line 9, the only "error" that exists is the one from line 8, and it's used in line 9. All done. "Error" was used. (We are warning about the redefined-outer-name going on, also.) Without |
Hold on! #2223 only presents cases in a module scope. There you have to use Here, I think the nested example is fine, because we have For instance, you just get one message here: def f():
x = 0
x = 0
So, I think we can close. |
Steps to reproduce
Given a file
a.py
:Current behavior
Expected behavior
pylint --version output
The text was updated successfully, but these errors were encountered: