Skip to content

Commit

Permalink
[refurb] Avoid bailing when reimplemented-operator is called on f…
Browse files Browse the repository at this point in the history
…unction (#9556)

Closes #9549.
  • Loading branch information
charliermarsh authored Jan 16, 2024
1 parent 8788d57 commit 45d374d
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::{bail, Result};
use anyhow::Result;

use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::{self as ast, Expr, Stmt};
Expand Down Expand Up @@ -80,7 +81,8 @@ pub(crate) fn reimplemented_operator(checker: &mut Checker, target: &FunctionLik
},
target.range(),
);
diagnostic.try_set_fix(|| target.try_fix(operator, checker.importer(), checker.semantic()));
diagnostic
.try_set_optional_fix(|| target.try_fix(operator, checker.importer(), checker.semantic()));
checker.diagnostics.push(diagnostic);
}

Expand Down Expand Up @@ -150,20 +152,20 @@ impl FunctionLike<'_> {
operator: &'static str,
importer: &Importer,
semantic: &SemanticModel,
) -> Result<Fix> {
) -> Result<Option<Fix>> {
match self {
Self::Lambda(_) => {
let (edit, binding) = importer.get_or_import_symbol(
&ImportRequest::import("operator", operator),
self.start(),
semantic,
)?;
Ok(Fix::safe_edits(
Ok(Some(Fix::safe_edits(
Edit::range_replacement(binding, self.range()),
[edit],
))
)))
}
Self::Function(_) => bail!("No fix available"),
Self::Function(_) => Ok(None),
}
}
}
Expand Down

0 comments on commit 45d374d

Please sign in to comment.