From 6f7a8ad560f03638a7efe59c80a29a47da16003e Mon Sep 17 00:00:00 2001 From: Brent Westbrook Date: Tue, 14 Jan 2025 10:51:58 -0500 Subject: [PATCH] set seen_default on fix generation error --- .../rules/fastapi_non_annotated_dependency.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/ruff_linter/src/rules/fastapi/rules/fastapi_non_annotated_dependency.rs b/crates/ruff_linter/src/rules/fastapi/rules/fastapi_non_annotated_dependency.rs index c65f0f6607bac..06327d0115734 100644 --- a/crates/ruff_linter/src/rules/fastapi/rules/fastapi_non_annotated_dependency.rs +++ b/crates/ruff_linter/src/rules/fastapi/rules/fastapi_non_annotated_dependency.rs @@ -176,7 +176,7 @@ fn create_diagnostic( if let (Some(annotation), Some(default)) = (¶meter.parameter.annotation, ¶meter.default) { - diagnostic.try_set_optional_fix(|| { + let mut try_generate_fix = || { let module = if checker.settings.target_version >= PythonVersion::Py39 { "typing" } else { @@ -251,7 +251,16 @@ fn create_diagnostic( }; let parameter_edit = Edit::range_replacement(content, parameter.range); Ok(Some(Fix::unsafe_edits(import_edit, [parameter_edit]))) - }); + }; + + // make sure we set `seen_default` if we bail out of `try_generate_fix` early. we could + // `match` on the result directly, but still calling `try_set_optional_fix` avoids + // duplicating the debug logging here + let fix: anyhow::Result> = try_generate_fix(); + if fix.is_err() { + seen_default = true; + } + diagnostic.try_set_optional_fix(|| fix); } checker.diagnostics.push(diagnostic);