We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Sample code:
def fix_out_of_range(x: int, min_x: int, max_x: int) -> int: if x < min_x: x = min_x if x > max_x: x = max_x return x
Command: ruff check --preview --select PLR test.py
ruff check --preview --select PLR test.py
Result:
test.py:3:2: PLR1730 [*] Replace `if` statement with `x = min(x, min_x)` | 2 | def fix_out_of_range(x: int, min_x: int, max_x: int) -> int: 3 | if x < min_x: | _____^ 4 | | x = min_x | |_________________^ PLR1730 5 | if x > max_x: 6 | x = max_x | = help: Replace with `x = min(x, min_x)` test.py:5:2: PLR1730 [*] Replace `if` statement with `x = max(x, max_x)` | 3 | if x < min_x: 4 | x = min_x 5 | if x > max_x: | _____^ 6 | | x = max_x | |_________________^ PLR1730 7 | return x | = help: Replace with `x = max(x, max_x)` Found 2 errors. [*] 2 fixable with the `--fix` option.
The min / max are reversed. The first one must be a max, second one min. Passing --fix will break the code:
max
min
--fix
def fix_out_of_range(x: int, min_x: int, max_x: int) -> int: x = min(x, min_x) x = max(x, max_x) return x
The correct fix:
def fix_out_of_range(x: int, min_x: int, max_x: int) -> int: x = max(x, min_x) x = min(x, max_x) return x
The text was updated successfully, but these errors were encountered:
Thanks, this is my bad.
Sorry, something went wrong.
Even looking at this error report I thought x = min(x, min_x) was correct initially. The reversing logic is breaking my brain.
x = min(x, min_x)
pylint
if-stmt-min-max
[pylint] Reverse min-max logic in if-stmt-min-max (#10890)
e7d1d43
Closes #10889.
[pylint] Reverse min-max logic in if-stmt-min-max (astral-sh#10890)
637859b
Closes astral-sh#10889.
charliermarsh
Successfully merging a pull request may close this issue.
Sample code:
Command:
ruff check --preview --select PLR test.py
Result:
The min / max are reversed.
The first one must be a
max
, second onemin
.Passing
--fix
will break the code:The correct fix:
The text was updated successfully, but these errors were encountered: