Skip to content

Conversation

danparizher
Copy link
Contributor

Summary

Fixes #19460

}
replacement_arg = chars.into_iter().collect();
}
}

Choose a reason for hiding this comment

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

Does this work for float("\x2dnan") or float("\N{HYPHEN-MINUS}nan")? Cf. #16771.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it covers both of those cases

Copy link
Contributor

@ntBre ntBre Jul 24, 2025

Choose a reason for hiding this comment

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

Could we add tests for those cases? I also think we could use the return value of as_non_finite_float_string_literal just above this instead of doing some of the manual manipulation ourselves. That should normalize the result so that we can just compare against "-nan" directly.

@ntBre ntBre self-requested a review July 24, 2025 13:07
@ntBre ntBre added bug Something isn't working fixes Related to suggested fixes for violations labels Jul 24, 2025
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

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

Thanks! Just a couple of suggestions

@@ -180,18 +180,18 @@ fn is_valid_argument_type(
typing::is_float(binding, semantic),
)
})
.unwrap_or_default()
.unwrap_or((false, false))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be equivalent, but it's probably more readable, even though I think I suggested the old version 😆

}
replacement_arg = chars.into_iter().collect();
}
}
Copy link
Contributor

@ntBre ntBre Jul 24, 2025

Choose a reason for hiding this comment

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

Could we add tests for those cases? I also think we could use the return value of as_non_finite_float_string_literal just above this instead of doing some of the manual manipulation ourselves. That should normalize the result so that we can just compare against "-nan" directly.

} else {
(false, false)
};

match (method_name, constructor) {
// Decimal.from_float accepts int, bool, float
// Decimal.from_float: Only int or bool are safe (float is unsafe due to FloatOperation trap)
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to update the name of this function and also the comment where it's called. is_valid made me think we would bail out without a diagnostic or without a fix if the result is invalid, but it's really just checking the fix safety.

Copy link
Contributor

github-actions bot commented Jul 24, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@danparizher danparizher requested a review from ntBre July 24, 2025 21:13
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

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

Thanks! Just one more tiny nit that I'll probably just apply and then merge this.

@ntBre ntBre enabled auto-merge (squash) July 28, 2025 14:18
@ntBre ntBre merged commit 201b079 into astral-sh:main Jul 28, 2025
34 checks passed
@danparizher danparizher deleted the fix-19460 branch July 28, 2025 14:33
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 has two problems related to Decimal.from_float
3 participants