`use-walrus-if` codemod introduces precedence bug
drdavella opened this issue · comments
Consider the following code:
condition = False in list_of_bools
if not condition:
do_something()
The codemod currently produces this change:
if not False in list_of_bools:
do_something()
This new code does not have the same semantics as the original code.
One possible fix would be to universally apply parentheses around rewritten conditions that are preceded by not
.
@drdavella I'm trying to figure out what you mean by not the same semantics... I think those two snippets are equivalent? the in
operator has a higher priority than the not
operator so as far as I'm concerned the second snip is equivalent to if not (False in list_of_bools):
I asked chatGPT because I started doubting myself and it agrees. Can you clarify or give an example where the two examples aren't the same?
You're right, maybe I'm confused about this. I'm trying to come up with a better example, but maybe I'm just off-base here 🤦♂️.
I'm going to close this for now because I'm 99% sure there's nothing to be done here.