You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
compare-with-tuple (SIM109) does not respect the or ordering in expressions. x or y == z or y == w should be turned into x or (y in (z, w)), but instead becomes y in (z, w) or x, changing the meaning of the code.
Other misc things about SIM109 I noticed:
The lint currently doesn't apply at all if there are comments inside the expr, but I don't know why. I think it should instead be a normally safe fix, and only unsafe if there are comments. (There is the same amount of __eq__ calls pre and post fix, ordering in those calls is preserved, and the code already doesn't lint if there is any possibility of other side effects.)
changed the title [-][`flake8-simplify`] `SIM109` does not respect `or` ordering (false positive)[/-][+][`flake8-simplify`] `SIM109` fix reorders statements incorrectly[/+]on Jun 25, 2025
Thanks, this seems like a bug. Maybe we can use OperatorPrecedence here.
With regard to the fix, I'm not sure if we want to upgrade it to a safe fix when there are no comments, but we could at least avoid the continue in the presence of comments since it's already unsafe.
Activity
[-][`flake8-simplify`] `SIM109` does not respect `or` ordering (false positive)[/-][+][`flake8-simplify`] `SIM109` fix reorders statements incorrectly[/+]ntBre commentedon Jun 25, 2025
Thanks, this seems like a bug. Maybe we can use
OperatorPrecedencehere.With regard to the fix, I'm not sure if we want to upgrade it to a safe fix when there are no comments, but we could at least avoid the
continuein the presence of comments since it's already unsafe.mikeleppane commentedon Aug 5, 2025
I'm working on this.
[flake8-simplify] Preserve operand order in SIM109 fix (#27824)