Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FURB157 has false negatives for non-finite float strings #14587

Closed
dscorbett opened this issue Nov 25, 2024 · 1 comment · Fixed by #14596
Closed

FURB157 has false negatives for non-finite float strings #14587

dscorbett opened this issue Nov 25, 2024 · 1 comment · Fixed by #14596
Labels
bug Something isn't working rule Implementing or modifying a lint rule

Comments

@dscorbett
Copy link

verbose-decimal-constructor (FURB157) has false negatives in Ruff 0.8.0 for some non-finite float strings. It recognizes the following strings case-insensitively in expressions like Decimal(float("inf")), but no others:

"inf" | "-inf" | "infinity" | "-infinity" | "nan"

float strips white space. For example, Decimal(float(" nan ")) should be simplified to Decimal(" nan "). It could be further normalized to Decimal("NaN"), but FURB157 does not currently normalize other float strings, so I think it should keep the string argument unchanged.

float allows both signs for all non-finite values. Decimal(float("+inf")), Decimal(float("+infinity")), Decimal(float("+nan")), and Decimal(float("-nan")) should be simplified. FURB157 should not normalize these string arguments either, except for the last one. Decimal(float("-nan")) is equivalent to Decimal("nan"), not Decimal("-nan"), so for an argument of "-nan", the sign character should be deleted.

@dylwil3
Copy link
Collaborator

dylwil3 commented Nov 25, 2024

Decimals strike again! Thanks for finding this, we'll get it fixed 😄

@dylwil3 dylwil3 added rule Implementing or modifying a lint rule bug Something isn't working labels Nov 25, 2024
dylwil3 added a commit that referenced this issue Dec 3, 2024
… (FURB157)` (#14596)

This PR extends the Decimal parsing used in [verbose-decimal-constructor
(FURB157)](https://docs.astral.sh/ruff/rules/verbose-decimal-constructor/)
to better handle non-finite `Decimal` objects, avoiding some false
negatives.

Closes #14587

---------

Co-authored-by: Micha Reiser <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants