Skip to content

[ruff] FURB164 Replace -nan with nan when using the value to construct Decimal#20391

Merged
dylwil3 merged 1 commit intoastral-sh:mainfrom
TaKO8Ki:fix-negative-nan-issue-for-furb164
Sep 19, 2025
Merged

[ruff] FURB164 Replace -nan with nan when using the value to construct Decimal#20391
dylwil3 merged 1 commit intoastral-sh:mainfrom
TaKO8Ki:fix-negative-nan-issue-for-furb164

Conversation

@TaKO8Ki
Copy link
Contributor

@TaKO8Ki TaKO8Ki commented Sep 15, 2025

Summary

Fixes #19699

Normalize Decimal(float("-nan")) to Decimal("nan").

The same handling is implemented in:

Test Plan

I've updated ruff_linter__rules__refurb__tests__FURB164_FURB164.py.snap.

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 {

@github-actions
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@dylwil3 dylwil3 self-requested a review September 15, 2025 13:27
Copy link
Collaborator

@dylwil3 dylwil3 left a comment

Choose a reason for hiding this comment

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

Thank you! I think the small amount of duplication is okay for now.

@dylwil3 dylwil3 merged commit 8eeca02 into astral-sh:main Sep 19, 2025
35 checks passed
@TaKO8Ki TaKO8Ki deleted the fix-negative-nan-issue-for-furb164 branch September 19, 2025 18:13
@dylwil3 dylwil3 added bug Something isn't working fixes Related to suggested fixes for violations labels Sep 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fixes Related to suggested fixes for violations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FURB164 fix changes behavior for negative NaN

2 participants