---
source: crates/ruff_linter/src/rules/pylint/mod.rs
---
PLR1730 [*] Replace `if` statement with `a = min(b, a)`
  --> if_stmt_min_max.py:21:1
   |
20 |   # case 1: a = min(b, a)
21 | / if a >= b:
22 | |     a = b
   | |_________^
23 |
24 |   # case 2: a = max(b, a)
   |
help: Replace with `a = min(b, a)`
   |
20 | # case 1: a = min(b, a)
   - if a >= b:
   -     a = b
21 + a = min(b, a)
22 |
   |

PLR1730 [*] Replace `if` statement with `a = max(b, a)`
  --> if_stmt_min_max.py:25:1
   |
24 |   # case 2: a = max(b, a)
25 | / if a <= b:
26 | |     a = b
   | |_________^
27 |
28 |   # case 3: b = min(a, b)
   |
help: Replace with `a = max(b, a)`
   |
24 | # case 2: a = max(b, a)
   - if a <= b:
   -     a = b
25 + a = max(b, a)
26 |
   |

PLR1730 [*] Replace `if` statement with `b = min(a, b)`
  --> if_stmt_min_max.py:29:1
   |
28 |   # case 3: b = min(a, b)
29 | / if a <= b:
30 | |     b = a
   | |_________^
31 |
32 |   # case 4: b = max(a, b)
   |
help: Replace with `b = min(a, b)`
   |
28 | # case 3: b = min(a, b)
   - if a <= b:
   -     b = a
29 + b = min(a, b)
30 |
   |

PLR1730 [*] Replace `if` statement with `b = max(a, b)`
  --> if_stmt_min_max.py:33:1
   |
32 |   # case 4: b = max(a, b)
33 | / if a >= b:
34 | |     b = a
   | |_________^
35 |
36 |   # case 5: a = min(a, b)
   |
help: Replace with `b = max(a, b)`
   |
32 | # case 4: b = max(a, b)
   - if a >= b:
   -     b = a
33 + b = max(a, b)
34 |
   |

PLR1730 [*] Replace `if` statement with `a = min(a, b)`
  --> if_stmt_min_max.py:37:1
   |
36 |   # case 5: a = min(a, b)
37 | / if a > b:
38 | |     a = b
   | |_________^
39 |
40 |   # case 6: a = max(a, b)
   |
help: Replace with `a = min(a, b)`
   |
36 | # case 5: a = min(a, b)
   - if a > b:
   -     a = b
37 + a = min(a, b)
38 |
   |

PLR1730 [*] Replace `if` statement with `a = max(a, b)`
  --> if_stmt_min_max.py:41:1
   |
40 |   # case 6: a = max(a, b)
41 | / if a < b:
42 | |     a = b
   | |_________^
43 |
44 |   # case 7: b = min(b, a)
   |
help: Replace with `a = max(a, b)`
   |
40 | # case 6: a = max(a, b)
   - if a < b:
   -     a = b
41 + a = max(a, b)
42 |
   |

PLR1730 [*] Replace `if` statement with `b = min(b, a)`
  --> if_stmt_min_max.py:45:1
   |
44 |   # case 7: b = min(b, a)
45 | / if a < b:
46 | |     b = a
   | |_________^
47 |
48 |   # case 8: b = max(b, a)
   |
help: Replace with `b = min(b, a)`
   |
44 | # case 7: b = min(b, a)
   - if a < b:
   -     b = a
45 + b = min(b, a)
46 |
   |

PLR1730 [*] Replace `if` statement with `b = max(b, a)`
  --> if_stmt_min_max.py:49:1
   |
48 |   # case 8: b = max(b, a)
49 | / if a > b:
50 | |     b = a
   | |_________^
   |
help: Replace with `b = max(b, a)`
   |
48 | # case 8: b = max(b, a)
   - if a > b:
   -     b = a
49 + b = max(b, a)
50 |
   |

PLR1730 [*] Replace `if` statement with `value = max(value, 10)`
  --> if_stmt_min_max.py:59:1
   |
58 |   # base case 6: value = max(value, 10)
59 | / if value < 10:
60 | |     value = 10
   | |______________^
61 |
62 |   # base case 2: value = max(10, value)
   |
help: Replace with `value = max(value, 10)`
   |
58 | # base case 6: value = max(value, 10)
   - if value < 10:
   -     value = 10
59 + value = max(value, 10)
60 |
   |

PLR1730 [*] Replace `if` statement with `value = max(10, value)`
  --> if_stmt_min_max.py:63:1
   |
62 |   # base case 2: value = max(10, value)
63 | / if value <= 10:
64 | |     value = 10
   | |______________^
65 |
66 |   # base case 6: value = max(value, value2)
   |
help: Replace with `value = max(10, value)`
   |
62 | # base case 2: value = max(10, value)
   - if value <= 10:
   -     value = 10
63 + value = max(10, value)
64 |
   |

PLR1730 [*] Replace `if` statement with `value = max(value, value2)`
  --> if_stmt_min_max.py:67:1
   |
66 |   # base case 6: value = max(value, value2)
67 | / if value < value2:
68 | |     value = value2
   | |__________________^
69 |
70 |   # base case 5: value = min(value, 10)
   |
help: Replace with `value = max(value, value2)`
   |
66 | # base case 6: value = max(value, value2)
   - if value < value2:
   -     value = value2
67 + value = max(value, value2)
68 |
   |

PLR1730 [*] Replace `if` statement with `value = min(value, 10)`
  --> if_stmt_min_max.py:71:1
   |
70 |   # base case 5: value = min(value, 10)
71 | / if value > 10:
72 | |     value = 10
   | |______________^
73 |
74 |   # base case 1: value = min(10, value)
   |
help: Replace with `value = min(value, 10)`
   |
70 | # base case 5: value = min(value, 10)
   - if value > 10:
   -     value = 10
71 + value = min(value, 10)
72 |
   |

PLR1730 [*] Replace `if` statement with `value = min(10, value)`
  --> if_stmt_min_max.py:75:1
   |
74 |   # base case 1: value = min(10, value)
75 | / if value >= 10:
76 | |     value = 10
   | |______________^
77 |
78 |   # base case 5: value = min(value, value2)
   |
help: Replace with `value = min(10, value)`
   |
74 | # base case 1: value = min(10, value)
   - if value >= 10:
   -     value = 10
75 + value = min(10, value)
76 |
   |

PLR1730 [*] Replace `if` statement with `value = min(value, value2)`
  --> if_stmt_min_max.py:79:1
   |
78 |   # base case 5: value = min(value, value2)
79 | / if value > value2:
80 | |     value = value2
   | |__________________^
   |
help: Replace with `value = min(value, value2)`
   |
78 | # base case 5: value = min(value, value2)
   - if value > value2:
   -     value = value2
79 + value = min(value, value2)
80 |
   |

PLR1730 [*] Replace `if` statement with `A1.value = max(A1.value, 10)`
  --> if_stmt_min_max.py:92:1
   |
92 | / if A1.value < 10:
93 | |     A1.value = 10
   | |_________________^
94 |
95 |   if A1.value > 10:
   |
help: Replace with `A1.value = max(A1.value, 10)`
   |
91 |
   - if A1.value < 10:
   -     A1.value = 10
92 + A1.value = max(A1.value, 10)
93 |
   |

PLR1730 [*] Replace `if` statement with `A1.value = min(A1.value, 10)`
  --> if_stmt_min_max.py:95:1
   |
93 |       A1.value = 10
94 |
95 | / if A1.value > 10:
96 | |     A1.value = 10
   | |_________________^
   |
help: Replace with `A1.value = min(A1.value, 10)`
   |
94 |
   - if A1.value > 10:
   -     A1.value = 10
95 + A1.value = min(A1.value, 10)
96 |
   |

PLR1730 [*] Replace `if` statement with `A2 = max(A2, A1)`
   --> if_stmt_min_max.py:119:1
    |
117 |   A2 = AA(3)
118 |
119 | / if A2 < A1:  # [max-instead-of-if]
120 | |     A2 = A1
    | |___________^
121 |
122 |   if A2 <= A1:  # [max-instead-of-if]
    |
help: Replace with `A2 = max(A2, A1)`
    |
118 |
    - if A2 < A1:  # [max-instead-of-if]
    -     A2 = A1
119 + A2 = max(A2, A1)
120 |
    |
note: This is an unsafe fix and may change runtime behavior

PLR1730 [*] Replace `if` statement with `A2 = max(A1, A2)`
   --> if_stmt_min_max.py:122:1
    |
120 |       A2 = A1
121 |
122 | / if A2 <= A1:  # [max-instead-of-if]
123 | |     A2 = A1
    | |___________^
124 |
125 |   if A2 > A1:  # [min-instead-of-if]
    |
help: Replace with `A2 = max(A1, A2)`
    |
121 |
    - if A2 <= A1:  # [max-instead-of-if]
    -     A2 = A1
122 + A2 = max(A1, A2)
123 |
    |
note: This is an unsafe fix and may change runtime behavior

PLR1730 [*] Replace `if` statement with `A2 = min(A2, A1)`
   --> if_stmt_min_max.py:125:1
    |
123 |       A2 = A1
124 |
125 | / if A2 > A1:  # [min-instead-of-if]
126 | |     A2 = A1
    | |___________^
127 |
128 |   if A2 >= A1:  # [min-instead-of-if]
    |
help: Replace with `A2 = min(A2, A1)`
    |
124 |
    - if A2 > A1:  # [min-instead-of-if]
    -     A2 = A1
125 + A2 = min(A2, A1)
126 |
    |
note: This is an unsafe fix and may change runtime behavior

PLR1730 [*] Replace `if` statement with `A2 = min(A1, A2)`
   --> if_stmt_min_max.py:128:1
    |
126 |       A2 = A1
127 |
128 | / if A2 >= A1:  # [min-instead-of-if]
129 | |     A2 = A1
    | |___________^
130 |
131 |   # Negative
    |
help: Replace with `A2 = min(A1, A2)`
    |
127 |
    - if A2 >= A1:  # [min-instead-of-if]
    -     A2 = A1
128 + A2 = min(A1, A2)
129 |
    |
note: This is an unsafe fix and may change runtime behavior

PLR1730 [*] Replace `if` statement with `min` call
   --> if_stmt_min_max.py:191:1
    |
190 |   # Parenthesized expressions
191 | / if value.attr > 3:
192 | |     (
193 | |         value.
194 | |         attr
195 | |     ) = 3
    | |_________^
196 |
197 |   class Foo:
    |
help: Replace with `min` call
    |
190 | # Parenthesized expressions
    - if value.attr > 3:
    -     (
191 + (
192 |         value.
193 |         attr
    -     ) = 3
194 +     ) = min(value.attr, 3)
195 |
    |

PLR1730 [*] Replace `if` statement with `self._min = min(self._min, value)`
   --> if_stmt_min_max.py:202:9
    |
201 |       def foo(self, value) -> None:
202 | /         if value < self._min:
203 | |             self._min = value
    | |_____________________________^
204 |           if value > self._max:
205 |               self._max = value
    |
help: Replace with `self._min = min(self._min, value)`
    |
201 |     def foo(self, value) -> None:
    -         if value < self._min:
    -             self._min = value
202 +         self._min = min(self._min, value)
203 |         if value > self._max:
    |

PLR1730 [*] Replace `if` statement with `self._max = max(self._max, value)`
   --> if_stmt_min_max.py:204:9
    |
202 |           if value < self._min:
203 |               self._min = value
204 | /         if value > self._max:
205 | |             self._max = value
    | |_____________________________^
206 |
207 |           if self._min < value:
    |
help: Replace with `self._max = max(self._max, value)`
    |
203 |             self._min = value
    -         if value > self._max:
    -             self._max = value
204 +         self._max = max(self._max, value)
205 |
    |

PLR1730 [*] Replace `if` statement with `self._min = max(self._min, value)`
   --> if_stmt_min_max.py:207:9
    |
205 |               self._max = value
206 |
207 | /         if self._min < value:
208 | |             self._min = value
    | |_____________________________^
209 |           if self._max > value:
210 |               self._max = value
    |
help: Replace with `self._min = max(self._min, value)`
    |
206 |
    -         if self._min < value:
    -             self._min = value
207 +         self._min = max(self._min, value)
208 |         if self._max > value:
    |

PLR1730 [*] Replace `if` statement with `self._max = min(self._max, value)`
   --> if_stmt_min_max.py:209:9
    |
207 |           if self._min < value:
208 |               self._min = value
209 | /         if self._max > value:
210 | |             self._max = value
    | |_____________________________^
211 |
212 |           if value <= self._min:
    |
help: Replace with `self._max = min(self._max, value)`
    |
208 |             self._min = value
    -         if self._max > value:
    -             self._max = value
209 +         self._max = min(self._max, value)
210 |
    |

PLR1730 [*] Replace `if` statement with `self._min = min(value, self._min)`
   --> if_stmt_min_max.py:212:9
    |
210 |               self._max = value
211 |
212 | /         if value <= self._min:
213 | |             self._min = value
    | |_____________________________^
214 |           if value >= self._max:
215 |               self._max = value
    |
help: Replace with `self._min = min(value, self._min)`
    |
211 |
    -         if value <= self._min:
    -             self._min = value
212 +         self._min = min(value, self._min)
213 |         if value >= self._max:
    |

PLR1730 [*] Replace `if` statement with `self._max = max(value, self._max)`
   --> if_stmt_min_max.py:214:9
    |
212 |           if value <= self._min:
213 |               self._min = value
214 | /         if value >= self._max:
215 | |             self._max = value
    | |_____________________________^
216 |
217 |           if self._min <= value:
    |
help: Replace with `self._max = max(value, self._max)`
    |
213 |             self._min = value
    -         if value >= self._max:
    -             self._max = value
214 +         self._max = max(value, self._max)
215 |
    |

PLR1730 [*] Replace `if` statement with `self._min = max(value, self._min)`
   --> if_stmt_min_max.py:217:9
    |
215 |               self._max = value
216 |
217 | /         if self._min <= value:
218 | |             self._min = value
    | |_____________________________^
219 |           if self._max >= value:
220 |               self._max = value
    |
help: Replace with `self._min = max(value, self._min)`
    |
216 |
    -         if self._min <= value:
    -             self._min = value
217 +         self._min = max(value, self._min)
218 |         if self._max >= value:
    |

PLR1730 [*] Replace `if` statement with `self._max = min(value, self._max)`
   --> if_stmt_min_max.py:219:9
    |
217 |           if self._min <= value:
218 |               self._min = value
219 | /         if self._max >= value:
220 | |             self._max = value
    | |_____________________________^
    |
help: Replace with `self._max = min(value, self._max)`
    |
218 |             self._min = value
    -         if self._max >= value:
    -             self._max = value
219 +         self._max = min(value, self._max)
220 |
    |

PLR1730 [*] Replace `if` statement with `counter["a"] = max(counter["b"], counter["a"])`
   --> if_stmt_min_max.py:226:1
    |
225 |   # base case 2: counter["a"] = max(counter["b"], counter["a"])
226 | / if counter["a"] <= counter["b"]:
227 | |     counter["a"] = counter["b"]
    | |_______________________________^
228 |
229 |   # case 3: counter["b"] = min(counter["a"], counter["b"])
    |
help: Replace with `counter["a"] = max(counter["b"], counter["a"])`
    |
225 | # base case 2: counter["a"] = max(counter["b"], counter["a"])
    - if counter["a"] <= counter["b"]:
    -     counter["a"] = counter["b"]
226 + counter["a"] = max(counter["b"], counter["a"])
227 |
    |

PLR1730 [*] Replace `if` statement with `counter["b"] = min(counter["a"], counter["b"])`
   --> if_stmt_min_max.py:230:1
    |
229 |   # case 3: counter["b"] = min(counter["a"], counter["b"])
230 | / if counter["a"] <= counter["b"]:
231 | |     counter["b"] = counter["a"]
    | |_______________________________^
232 |
233 |   # case 5: counter["a"] = min(counter["a"], counter["b"])
    |
help: Replace with `counter["b"] = min(counter["a"], counter["b"])`
    |
229 | # case 3: counter["b"] = min(counter["a"], counter["b"])
    - if counter["a"] <= counter["b"]:
    -     counter["b"] = counter["a"]
230 + counter["b"] = min(counter["a"], counter["b"])
231 |
    |

PLR1730 [*] Replace `if` statement with `counter["b"] = max(counter["b"], counter["a"])`
   --> if_stmt_min_max.py:234:1
    |
233 |   # case 5: counter["a"] = min(counter["a"], counter["b"])
234 | / if counter["a"] > counter["b"]:
235 | |     counter["b"] = counter["a"]
    | |_______________________________^
236 |
237 |   # case 8: counter["a"] = max(counter["b"], counter["a"])
    |
help: Replace with `counter["b"] = max(counter["b"], counter["a"])`
    |
233 | # case 5: counter["a"] = min(counter["a"], counter["b"])
    - if counter["a"] > counter["b"]:
    -     counter["b"] = counter["a"]
234 + counter["b"] = max(counter["b"], counter["a"])
235 |
    |

PLR1730 [*] Replace `if` statement with `counter["b"] = max(counter["b"], counter["a"])`
   --> if_stmt_min_max.py:238:1
    |
237 |   # case 8: counter["a"] = max(counter["b"], counter["a"])
238 | / if counter["a"] > counter["b"]:
239 | |     counter["b"] = counter["a"]
    | |_______________________________^
240 |
241 |   # https://github.com/astral-sh/ruff/issues/17311
    |
help: Replace with `counter["b"] = max(counter["b"], counter["a"])`
    |
237 | # case 8: counter["a"] = max(counter["b"], counter["a"])
    - if counter["a"] > counter["b"]:
    -     counter["b"] = counter["a"]
238 + counter["b"] = max(counter["b"], counter["a"])
239 |
    |

PLR1730 [*] Replace `if` statement with `a = min(b, a)`
   --> if_stmt_min_max.py:245:1
    |
243 |   # fix marked unsafe as delete comments
244 |   a, b = [], []
245 | / if a >= b:
246 | |     # very important comment
247 | |     a = b
    | |_________^
248 |
249 |   # fix marked safe as preserve comments
    |
help: Replace with `a = min(b, a)`
    |
244 | a, b = [], []
    - if a >= b:
    -     # very important comment
    -     a = b
245 + a = min(b, a)
246 |
    |
note: This is an unsafe fix and may change runtime behavior

PLR1730 [*] Replace `if` statement with `a = min(b, a)`
   --> if_stmt_min_max.py:250:1
    |
249 |   # fix marked safe as preserve comments
250 | / if a >= b:
251 | |     a = b  # very important comment
    | |_________^
    |
help: Replace with `a = min(b, a)`
    |
249 | # fix marked safe as preserve comments
    - if a >= b:
    -     a = b  # very important comment
250 + a = min(b, a)  # very important comment
    |
