-
-
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
Fix false-negative of unused-variable on catched exceptions #4519
Conversation
This commit fixes a bug of false-negative on the unused-variable error in case of catched exception when used in the inner context.
Hi @ksaketou, thank you for the merge request. I had a look and the tests are very nice. I feel that the fix although it works, is too specific to the problem and I feel the performance and clarity of the code would be impacted. I don't know what would be the best way to fix this (It's possible to check how flake8 does it because it detect this error), but probably by doing something more generic like checking that the variable was not redefined before being used in all contexts, and not only when there is two imbricated try except. We could merge the test alone and add a TODO where pylint do not work properly yet so we can reuse them later if you want. |
I agree that the code is more specific than it should be, but I think that this case is pretty specific as well so I don't know how I could implement it in a more general way. I thought that since the bug only existed in the try/except cases, that that's what I had to work on. I will check flake8 and try to fix the bug. So, I shouldn't focus only on the try/except cases? Any suggestions are welcome 😄 Of course we can merge just the tests for now until I figure this out :) |
I'm working on a new branch for the addition of the tests but when I run |
Can you try to upgrade your dependencies in the virtualenv ? I think you need to have astroid 2.5.7 now. |
Hello @Pierre-Sassoulas , it's okay, indeed I had difficulty finding a solution that works and is also elegant. I think we can close this PR. |
Understood. Sorry again for the bad experience. |
Steps
doc/whatsnew/<current release.rst>
.Description
This pull request fixes a false-negative of the
unused-variable
error message caused in case of catched exception inside anotherexcept
block. It adds a new function for checking the content of the except block forraise
andprint
statements and also other try/except blocks.Type of Changes
Related Issue
Closes #4391