-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[
pylint
] Correct ordering of arguments in fix for if-stmt-min-max
…
… (`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>
- Loading branch information
1 parent
366ae1f
commit ae1b381
Showing
3 changed files
with
745 additions
and
415 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.