-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Regression used-before-assignment
with try-except
#5500
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
Comments
Thanks for finding the case.
This part is simple. I'll push a PR.
I'm not certain we need to require this. What if one of the except blocks returns or raises? This might get quite tangled given the current implementation of the variables checker. If we merge the PR I'm about to submit for this issue, thereby reducing false-positives, the false-negative where one except block doesn't happen to define a name could be evaluated for feasibility separately (given that we would need to check each handler for a return/raise). |
…assignments in except blocks following try blocks that return
…assignments in except blocks following try blocks that return
True.
IMO preventing |
Bug description
#5402 added the
used-before-assignment
error in cases an assignment only happens inexcept
blocks.While testing, I came across the example below. It's a special case, but I believe it should still be possible to exclude it.
try
block should returnexcept
block defines the variable/CC: @jacobtylerwalls
Configuration
No response
Command used
Pylint output
E0601: Using variable 'data' before assignment (used-before-assignment)
Expected behavior
No error
Pylint version
OS / Environment
No response
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: