-
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
PLR1730 fix for <=
and >=
orders equal arguments wrong
#16040
Labels
bug
Something isn't working
fixes
Related to suggested fixes for violations
help wanted
Contributions especially welcome
Comments
Oh sorry... This is my fault 🙈 Can I re-fix it? Now I understand better the problem, and I would like to remediate. |
@VascoSch92 of course! |
Don't worry. This is really on me. I should have caught that during the review. Thanks for taking another try at it. |
MichaReiser
added a commit
that referenced
this issue
Feb 12, 2025
… (`PLR1730`) (#16080) The PR addresses the issue #16040 . --- The logic used into the rule is the following: Suppose to have an expression of the form ```python if a cmp b: c = d ``` where `a`,` b`, `c` and `d` are Python obj and `cmp` one of `<`, `>`, `<=`, `>=`. Then: - `if a=c and b=d` - if `<=` fix with `a = max(b, a)` - if `>=` fix with `a = min(b, a)` - if `>` fix with `a = min(a, b)` - if `<` fix with `a = max(a, b)` - `if a=d and b=c` - if `<=` fix with `b = min(a, b)` - if `>=` fix with `b = max(a, b)` - if `>` fix with `b = max(b, a)` - if `<` fix with `b = min(b, a)` - do nothing, i.e., we cannot fix this case. --- In total we have 8 different and possible cases. ``` | Case | Expression | Fix | |-------|------------------|---------------| | 1 | if a >= b: a = b | a = min(b, a) | | 2 | if a <= b: a = b | a = max(b, a) | | 3 | if a <= b: b = a | b = min(a, b) | | 4 | if a >= b: b = a | b = max(a, b) | | 5 | if a > b: a = b | a = min(a, b) | | 6 | if a < b: a = b | a = max(a, b) | | 7 | if a < b: b = a | b = min(b, a) | | 8 | if a > b: b = a | b = max(b, a) | ``` I added them in the tests. Please double-check that I didn't make any mistakes. It's quite easy to mix up > and <. --------- Co-authored-by: Micha Reiser <micha@reiser.io>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
Something isn't working
fixes
Related to suggested fixes for violations
help wanted
Contributions especially welcome
Description
The fix for
if-stmt-min-max
(PLR1730) in Ruff 0.9.5 changes the program’s behavior when the operator is<=
or>=
and the values are equal. Of the following four examples, the first two were broken by #15930, and the last two were already incorrect.The text was updated successfully, but these errors were encountered: