[ruff] FURB164 Replace -nan with nan when using the value to construct Decimal#20391
Merged
dylwil3 merged 1 commit intoastral-sh:mainfrom Sep 19, 2025
Merged
Conversation
TaKO8Ki
commented
Sep 15, 2025
| let replacement_text = format!( | ||
| r#"{constructor_name}("{}")"#, | ||
| // `Decimal.from_float(float(" -nan")) == Decimal("nan")` | ||
| if normalized == "-nan" { |
Contributor
Author
There was a problem hiding this comment.
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.
Contributor
|
dylwil3
approved these changes
Sep 19, 2025
Collaborator
dylwil3
left a comment
There was a problem hiding this comment.
Thank you! I think the small amount of duplication is okay for now.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #19699
Normalize
Decimal(float("-nan"))toDecimal("nan").The same handling is implemented in:
ruff/crates/ruff_linter/src/rules/refurb/rules/verbose_decimal_constructor.rs
Line 165 in c3e873d
Test Plan
I've updated
ruff_linter__rules__refurb__tests__FURB164_FURB164.py.snap.