|
1 |
| -use anyhow::{bail, Result}; |
| 1 | +use anyhow::Result; |
| 2 | + |
2 | 3 | use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
|
3 | 4 | use ruff_macros::{derive_message_formats, violation};
|
4 | 5 | use ruff_python_ast::{self as ast, Expr, Stmt};
|
@@ -80,7 +81,8 @@ pub(crate) fn reimplemented_operator(checker: &mut Checker, target: &FunctionLik
|
80 | 81 | },
|
81 | 82 | target.range(),
|
82 | 83 | );
|
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())); |
84 | 86 | checker.diagnostics.push(diagnostic);
|
85 | 87 | }
|
86 | 88 |
|
@@ -150,20 +152,20 @@ impl FunctionLike<'_> {
|
150 | 152 | operator: &'static str,
|
151 | 153 | importer: &Importer,
|
152 | 154 | semantic: &SemanticModel,
|
153 |
| - ) -> Result<Fix> { |
| 155 | + ) -> Result<Option<Fix>> { |
154 | 156 | match self {
|
155 | 157 | Self::Lambda(_) => {
|
156 | 158 | let (edit, binding) = importer.get_or_import_symbol(
|
157 | 159 | &ImportRequest::import("operator", operator),
|
158 | 160 | self.start(),
|
159 | 161 | semantic,
|
160 | 162 | )?;
|
161 |
| - Ok(Fix::safe_edits( |
| 163 | + Ok(Some(Fix::safe_edits( |
162 | 164 | Edit::range_replacement(binding, self.range()),
|
163 | 165 | [edit],
|
164 |
| - )) |
| 166 | + ))) |
165 | 167 | }
|
166 |
| - Self::Function(_) => bail!("No fix available"), |
| 168 | + Self::Function(_) => Ok(None), |
167 | 169 | }
|
168 | 170 | }
|
169 | 171 | }
|
|
0 commit comments