From 6730350bbd4480ec06c2f8a1a5d2171bcbc9e512 Mon Sep 17 00:00:00 2001 From: Harutaka Kawamura Date: Mon, 29 Dec 2025 23:17:33 +0900 Subject: [PATCH] [`refurb`] Mark `FURB192` fix as always unsafe (#22210) ## Summary Close #22204 ## Test Plan Existing checks --- .../ruff_linter/src/rules/refurb/rules/sorted_min_max.rs | 8 ++------ ..._linter__rules__refurb__tests__FURB192_FURB192.py.snap | 6 ++++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/ruff_linter/src/rules/refurb/rules/sorted_min_max.rs b/crates/ruff_linter/src/rules/refurb/rules/sorted_min_max.rs index a6187ccaee..e2b4018865 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/sorted_min_max.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/sorted_min_max.rs @@ -41,7 +41,7 @@ use crate::checkers::ast::Checker; /// the same key. However, `min(data, key=itemgetter(0))` will return the _first_ /// "minimum" element in the list in the same scenario. /// -/// As such, this rule's fix is marked as unsafe when the `reverse` keyword is used. +/// As such, this rule's fix is marked as unsafe. /// /// ## References /// - [Python documentation: `min`](https://docs.python.org/3/library/functions.html#min) @@ -193,11 +193,7 @@ pub(crate) fn sorted_min_max(checker: &Checker, subscript: &ast::ExprSubscript) }; let replacement = Edit::range_replacement(replacement, subscript.range()); - if is_reversed { - Fix::unsafe_edit(replacement) - } else { - Fix::safe_edit(replacement) - } + Fix::unsafe_edit(replacement) }); } } diff --git a/crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB192_FURB192.py.snap b/crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB192_FURB192.py.snap index 120e2db30f..440f2e3df3 100644 --- a/crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB192_FURB192.py.snap +++ b/crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB192_FURB192.py.snap @@ -19,6 +19,7 @@ help: Replace with `min` 4 | 5 | sorted(l)[-1] 6 | +note: This is an unsafe fix and may change runtime behavior FURB192 [*] Prefer `max` over `sorted()` to compute the maximum value in a sequence --> FURB192.py:5:1 @@ -39,6 +40,7 @@ help: Replace with `max` 6 | 7 | sorted(l, reverse=False)[-1] 8 | +note: This is an unsafe fix and may change runtime behavior FURB192 [*] Prefer `max` over `sorted()` to compute the maximum value in a sequence --> FURB192.py:7:1 @@ -59,6 +61,7 @@ help: Replace with `max` 8 | 9 | sorted(l, key=lambda x: x)[0] 10 | +note: This is an unsafe fix and may change runtime behavior FURB192 [*] Prefer `min` over `sorted()` to compute the minimum value in a sequence --> FURB192.py:9:1 @@ -79,6 +82,7 @@ help: Replace with `min` 10 | 11 | sorted(l, key=key_fn)[0] 12 | +note: This is an unsafe fix and may change runtime behavior FURB192 [*] Prefer `min` over `sorted()` to compute the minimum value in a sequence --> FURB192.py:11:1 @@ -99,6 +103,7 @@ help: Replace with `min` 12 | 13 | sorted([1, 2, 3])[0] 14 | +note: This is an unsafe fix and may change runtime behavior FURB192 [*] Prefer `min` over `sorted()` to compute the minimum value in a sequence --> FURB192.py:13:1 @@ -119,6 +124,7 @@ help: Replace with `min` 14 | 15 | # Unsafe 16 | +note: This is an unsafe fix and may change runtime behavior FURB192 [*] Prefer `min` over `sorted()` to compute the minimum value in a sequence --> FURB192.py:17:1