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
Emit unused-variable for unused exceptions in exception handlers #2223
Comments
This is intended. We're only emitting in some conditions for What should we fix though is the second example, we should emit that |
hmm that's true, that's why I also mentioned the valid case. |
@PCManticore is there any function like is_name_used_in_scope in checkers/utils.py? |
Duplicate of #626, which was fixed. Suggest closing. |
@jacobtylerwalls it looks like it's not exactly the same thing, we still do not emit warning for the snippet provided in the issue: $ cat a.py
try:
a = 1/0
except ArithmeticError as e:
print('ArithmeticError occurred')
$ pylint a.py --enable=all --enable-all-extensions
************* Module a
a.py:1:0: C0114: Missing module docstring (missing-module-docstring)
------------------------------------------------------------------
Your code has been rated at 7.50/10 (previous run: 7.50/10, +0.00) |
True, thank you. Closely related to #4391. |
These examples were only presented at the module-level. These work with try:
a = 1/0
except ArithmeticError as e:
print('ArithmeticError occurred')
For function examples, see discussion at #4391 about whether we need more handling. |
Steps to reproduce
Current behavior
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
Expected behavior
pylint should give a warning that only pass statement is in the except block, as the exception is simply consumed without doing meaningful operation on it.
This issue occurs occasionally, as I personally write skeleton try/except block with pass and later on add either logging or re raising exception code in except block after completing the main code in try block. However sometimes I just miss some except blocks and this message should highlight this issue.
Note: Although this is sometimes expected behavior, but if not, then can lead to subtle bugs.
pylint --version output
pylint 2.0.0.dev1
astroid 2.0.0.dev3
Python 3.6.4 (default, Jan 7 2018, 15:53:53)
[GCC 6.4.0]
Another similar issue but somewhat minor than above one is:
Steps to reproduce
Current behavior
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
Expected behavior
pylint should give a warning that variable 'e' is not used in the except block.
The text was updated successfully, but these errors were encountered: