Skip to content

FURB164 fix does not consistently simplify expressions containing non-finite float strings #16559

Description

@dscorbett

Summary

unnecessary-from-float (FURB164) does not consistently simplify expressions containing non-finite float strings. This is similar to #14587. A non-finite float string can having leading or trailing white space. It can also have an otiose sign: +inf, +nan, or -nan. FURB164 only recognizes strings without these extras. It should treat them the same and fix all or none of them.

$ cat >furb164.py <<'# EOF'
from decimal import Decimal
Decimal.from_float(float("\n+nan\n"))
Decimal.from_float(float("\xa0-nan\u3000"))
Decimal.from_float(float(" +inf "))
# cf.:
Decimal.from_float(float("nan"))
Decimal.from_float(float("-inf"))
# EOF

$ ruff --isolated check --preview --select FURB164 furb164.py --fix
Found 5 errors (5 fixed, 0 remaining).

$ cat furb164.py
from decimal import Decimal
Decimal(float("\n+nan\n"))
Decimal(float("\xa0-nan\u3000"))
Decimal(float(" +inf "))
# cf.:
Decimal("nan")
Decimal("-inf")

For those first three examples, the fix should produce:

Decimal("\n+nan\n")
Decimal("\xa0nan\u3000")
Decimal(" +inf ")

Note that the sign should be removed from -nan. Otherwise, the strings stay the same.

Alternatively, the removal of the float call could be considered out of scope for this rule because verbose-decimal-constructor (FURB157) already handles it. In that case, FURB164 should convert Decimal.from_float(float("nan")) (for example) to Decimal(float("nan")) instead of simplifying it to Decimal("nan").

Version

ruff 0.9.10 (0dfa810 2025-03-07)

Activity

  1. added
    bugAn issue describing something that isn't working, or a PR that fixes a bug
    on Mar 7, 2025
  2. added
    ruleImplementing or modifying a lint rule
    wishNot on the current roadmap; maybe in the future
    and removed
    bugAn issue describing something that isn't working, or a PR that fixes a bug
    on Mar 14, 2025
  3. charliermarsh commented on May 29, 2026

    @charliermarsh
    Member

    I think this was fixed by #18925 and #20391.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ruleImplementing or modifying a lint rulewishNot on the current roadmap; maybe in the future

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions