-
-
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
Fix #5500: Fix false-positive used-before-assignment
for assignments in except blocks following try blocks that return
#5506
Conversation
Pull Request Test Coverage Report for Build 1573137423
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I think it's a clever fix to bring better control flow.
Fix itself seems fine, but this should be documented in the description of the |
9ba2ecc
to
11e7299
Compare
Sorry for the extra force push, I pushed a comment to the wrong branch and removed it when I discovered it to avoid cluttering the branch history. |
…assignments in except blocks following try blocks that return
d3cc906
to
8542652
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks good and indeed fixes the false-positives.
One thing I noticed though is that the filtered_nodes
list comprehension has gotten rather complicated with multiple nested ifs and comprehensions itself. This should probably be a function instead.
That would also allow n.statement()
to be cached witch would improve performance at least a tiny bit.
Could you create a followup PR for it?
Sure thing--I agree, the comprehension is quite ugly now. |
Type of Changes
Description
Fixes false positive for
used-before-assignment
when evaluating statements after except handlers where the correspondingtry
returned. In this scenario, we should assume one of the except handlers did execute.There is the potential for a false-negative where only ONE of the except handlers defines the variable in question, but to check that, we would need to permit scenarios where the other except handlers merely raise or return--that case shouldn't emit a warning. I think the feasibility of that should be evaluated separately.
Closes #5500