Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,19 @@ fn handle_non_finite_float_special_case(
return None;
};
let normalized = as_non_finite_float_string_literal(float_arg)?;
let replacement_text = format!(r#"{constructor_name}("{normalized}")"#);
let replacement_text = format!(
r#"{constructor_name}("{}")"#,
// `Decimal.from_float(float(" -nan")) == Decimal("nan")`
if normalized == "-nan" {
Copy link
Contributor Author

@TaKO8Ki TaKO8Ki Sep 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same handling is implemented in:

Is it better to embed this handling into as_non_finite_float_string_literal? Since Apart from unnecessary_from_float, the function is used only in the following place, it does not affect other parts, but I feel it's too specific.

let Some(float_str) = as_non_finite_float_string_literal(float) else {

// Here we do not attempt to remove just the '-' character.
// It may have been encoded (e.g. as '\N{hyphen-minus}')
// in the original source slice, and the added complexity
// does not make sense for this edge case.
"nan"
} else {
normalized
}
);
Some(Edit::range_replacement(replacement_text, call.range()))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ help: Replace with `Decimal` constructor
21 | _ = Decimal.from_float(float("-Infinity"))
22 | _ = Decimal.from_float(float("nan"))
- _ = Decimal.from_float(float("-NaN "))
23 + _ = Decimal("-nan")
23 + _ = Decimal("nan")
24 | _ = Decimal.from_float(float(" \n+nan \t"))
25 | _ = Decimal.from_float(float(" iNf \n\t "))
26 | _ = Decimal.from_float(float("  -inF\n \t"))
Expand Down Expand Up @@ -655,7 +655,7 @@ help: Replace with `Decimal` constructor
62 |
63 | # Cases with non-finite floats - should produce safe fixes
- _ = Decimal.from_float(float("-nan"))
64 + _ = Decimal("-nan")
64 + _ = Decimal("nan")
65 | _ = Decimal.from_float(float("\x2dnan"))
66 | _ = Decimal.from_float(float("\N{HYPHEN-MINUS}nan"))

Expand All @@ -673,7 +673,7 @@ help: Replace with `Decimal` constructor
63 | # Cases with non-finite floats - should produce safe fixes
64 | _ = Decimal.from_float(float("-nan"))
- _ = Decimal.from_float(float("\x2dnan"))
65 + _ = Decimal("-nan")
65 + _ = Decimal("nan")
66 | _ = Decimal.from_float(float("\N{HYPHEN-MINUS}nan"))

FURB164 [*] Verbose method `from_float` in `Decimal` construction
Expand All @@ -689,4 +689,4 @@ help: Replace with `Decimal` constructor
64 | _ = Decimal.from_float(float("-nan"))
65 | _ = Decimal.from_float(float("\x2dnan"))
- _ = Decimal.from_float(float("\N{HYPHEN-MINUS}nan"))
66 + _ = Decimal("-nan")
66 + _ = Decimal("nan")
Loading