Skip to content

Commit 6950c93

Browse files
authored
Make C413 fix as suggested for reversed call (#4891)
1 parent ae75b30 commit 6950c93

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

crates/ruff/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustpython_parser::ast::{self, Expr, Ranged};
22

3-
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic};
3+
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
44
use ruff_macros::{derive_message_formats, violation};
55

66
use crate::checkers::ast::Checker;
@@ -85,9 +85,14 @@ pub(crate) fn unnecessary_call_around_sorted(
8585
expr.range(),
8686
);
8787
if checker.patch(diagnostic.kind.rule()) {
88-
#[allow(deprecated)]
89-
diagnostic.try_set_fix_from_edit(|| {
90-
fixes::fix_unnecessary_call_around_sorted(checker.locator, checker.stylist, expr)
88+
diagnostic.try_set_fix(|| {
89+
let edit =
90+
fixes::fix_unnecessary_call_around_sorted(checker.locator, checker.stylist, expr)?;
91+
if outer == "reversed" {
92+
Ok(Fix::suggested(edit))
93+
} else {
94+
Ok(Fix::automatic(edit))
95+
}
9196
});
9297
}
9398
checker.diagnostics.push(diagnostic);

crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C413_C413.py.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ C413.py:3:1: C413 [*] Unnecessary `list` call around `sorted()`
1212
|
1313
= help: Remove unnecessary `list` call
1414

15-
Suggested fix
15+
Fix
1616
1 1 | x = [2, 3, 1]
1717
2 2 | list(x)
1818
3 |-list(sorted(x))

0 commit comments

Comments
 (0)