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

Open
dscorbett opened this issue Nov 25, 2024 · 1 comment · May be fixed by #14596
Open

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

dscorbett opened this issue Nov 25, 2024 · 1 comment · May be 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
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