-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
unused-variable
false negative on a caught exception in the latest 3.x alpha release
#8595
Comments
My git bisect suggests this might have been a regression caused by #8441 |
Hi @yilei, thanks for the report and bisect. I was surprised: I would have expected we weren't warning about this case. Generally, when you define a variable like I'll leave this open for a bit to see what others think. |
Ah, this was not very obvious in the exception catching cases. Feel free to close this then. I can send a PR to add a test case if you think it would benefit? |
Yes, please do, thank you! |
@jacobtylerwalls Hmm, actually, it does raise # pylint: disable=missing-module-docstring,missing-function-docstring
import logging
def func1(module):
try:
module.compute()
except module.TimeoutError as exc:
logging.error('Timed out: %s', exc)
try:
module.compute(timeout=1200)
except module.Error as exc:
pass
def func2(module):
try:
module.compute()
error = False
except module.TimeoutError as exc:
logging.error('Timed out: %s', exc)
error = True
if error:
# Try again with larger timeout.
try:
module.compute(timeout=1200)
except module.Error as exc:
pass
(Unassigning myself for now since this needs a decision and isn't just a test case anymore.) |
Thanks for the test cases. I guess we can continue special-casing exception handlers in this instance. I'm not sure exactly when that was introduced, but #4791 looks relevant. Thanks for the report. |
Bug description
Configuration
No response
Command used
Pylint output
Expected behavior
It should raise
unused-variable
for the seconde
:************* Module unused
t.py:15:4: W0612: Unused variable 'e' (unused-variable)
Your code has been rated at 9.23/10 (previous run: 10.00/10, -0.77)
Pylint version
OS / Environment
No response
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: