Skip to content

Commit

Permalink
Make C413 fix as suggested for reversed call (#4891)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila authored Jun 7, 2023
1 parent ae75b30 commit 6950c93
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustpython_parser::ast::{self, Expr, Ranged};

use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic};
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix};
use ruff_macros::{derive_message_formats, violation};

use crate::checkers::ast::Checker;
Expand Down Expand Up @@ -85,9 +85,14 @@ pub(crate) fn unnecessary_call_around_sorted(
expr.range(),
);
if checker.patch(diagnostic.kind.rule()) {
#[allow(deprecated)]
diagnostic.try_set_fix_from_edit(|| {
fixes::fix_unnecessary_call_around_sorted(checker.locator, checker.stylist, expr)
diagnostic.try_set_fix(|| {
let edit =
fixes::fix_unnecessary_call_around_sorted(checker.locator, checker.stylist, expr)?;
if outer == "reversed" {
Ok(Fix::suggested(edit))
} else {
Ok(Fix::automatic(edit))
}
});
}
checker.diagnostics.push(diagnostic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ C413.py:3:1: C413 [*] Unnecessary `list` call around `sorted()`
|
= help: Remove unnecessary `list` call

Suggested fix
Fix
1 1 | x = [2, 3, 1]
2 2 | list(x)
3 |-list(sorted(x))
Expand Down

0 comments on commit 6950c93

Please sign in to comment.