Skip to content

Commit

Permalink
set seen_default on fix generation error
Browse files Browse the repository at this point in the history
  • Loading branch information
ntBre committed Jan 14, 2025
1 parent 3335c03 commit 6f7a8ad
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ fn create_diagnostic(

if let (Some(annotation), Some(default)) = (&parameter.parameter.annotation, &parameter.default)
{
diagnostic.try_set_optional_fix(|| {
let mut try_generate_fix = || {
let module = if checker.settings.target_version >= PythonVersion::Py39 {
"typing"
} else {
Expand Down Expand Up @@ -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<Option<Fix>> = try_generate_fix();
if fix.is_err() {
seen_default = true;
}
diagnostic.try_set_optional_fix(|| fix);
}

checker.diagnostics.push(diagnostic);
Expand Down

0 comments on commit 6f7a8ad

Please sign in to comment.