-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix #5112: Prevent used-before-assignment
if named expression found first in container
#5812
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 #5112: Prevent used-before-assignment
if named expression found first in container
#5812
Conversation
β¦ound first in container
Pull Request Test Coverage Report for Build 1860771448
π - 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.
I don't know about where to put this. On one hand this is a bug fix, it feels wrong not to put it in if the work is done. On the other hand we have a LOT of thing in 2.13 already and we need to focus on actually releasing at some point. We can probably put this in 2.13 as I took the time to review now.
Co-authored-by: Pierre Sassoulas <[email protected]>
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.
There's been a new issue opened regarding this problem, I think we could add this regression test, what do you think ?
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.
Sounds good to me.
|
||
def expression_in_ternary_operator_inside_container_wrong_position(): | ||
"""2-element list where named expression comes too late""" | ||
return [val3, val3 if (val3 := 'something') else 'anything'] # [used-before-assignment] |
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.
Pff... Man that's convoluted. Can't we raise an don't-write-code-like-this
warning here? π
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.
Haha, I had to take 2-3mn and run the code to understand myself π But do we really want to make the kind of person that would write this, flock to our bug tracker to complain π ?
Type of Changes
Description
Prevent a false positive for
used-before-assignment
when a named expression (walrus operator) is found first in a container.For instance, this passed:
But this didn't (it's a tuple):
Notice this should not pass:
Closes #5112
Of course, this can wait for 2.14, no problem.