Skip to content

Commit 45d374d

Browse files
[refurb] Avoid bailing when reimplemented-operator is called on function (#9556)
Closes #9549.
1 parent 8788d57 commit 45d374d

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

crates/ruff_linter/src/rules/refurb/rules/reimplemented_operator.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use anyhow::{bail, Result};
1+
use anyhow::Result;
2+
23
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
34
use ruff_macros::{derive_message_formats, violation};
45
use ruff_python_ast::{self as ast, Expr, Stmt};
@@ -80,7 +81,8 @@ pub(crate) fn reimplemented_operator(checker: &mut Checker, target: &FunctionLik
8081
},
8182
target.range(),
8283
);
83-
diagnostic.try_set_fix(|| target.try_fix(operator, checker.importer(), checker.semantic()));
84+
diagnostic
85+
.try_set_optional_fix(|| target.try_fix(operator, checker.importer(), checker.semantic()));
8486
checker.diagnostics.push(diagnostic);
8587
}
8688

@@ -150,20 +152,20 @@ impl FunctionLike<'_> {
150152
operator: &'static str,
151153
importer: &Importer,
152154
semantic: &SemanticModel,
153-
) -> Result<Fix> {
155+
) -> Result<Option<Fix>> {
154156
match self {
155157
Self::Lambda(_) => {
156158
let (edit, binding) = importer.get_or_import_symbol(
157159
&ImportRequest::import("operator", operator),
158160
self.start(),
159161
semantic,
160162
)?;
161-
Ok(Fix::safe_edits(
163+
Ok(Some(Fix::safe_edits(
162164
Edit::range_replacement(binding, self.range()),
163165
[edit],
164-
))
166+
)))
165167
}
166-
Self::Function(_) => bail!("No fix available"),
168+
Self::Function(_) => Ok(None),
167169
}
168170
}
169171
}

0 commit comments

Comments
 (0)