Summary
Some fixes of unnecessary-from-float (FURB164) are marked unsafe but are actually safe: when the argument is specified as a keyword argument but would otherwise be marked safe, and when the argument to Fraction.from_decimal is a Decimal. Example:
$ cat >furb164.py <<'# EOF'
from decimal import Decimal
from fractions import Fraction
print(Fraction.from_float(f=4.2))
print(Fraction.from_decimal(dec=4))
print(Fraction.from_decimal(Decimal("4.2")))
print(Fraction.from_decimal(dec=Decimal("4.2")))
# EOF
$ python furb164.py
4728779608739021/1125899906842624
4
21/5
21/5
$ ruff --isolated check furb164.py --select FURB164 --preview --output-format concise -q
furb164.py:3:7: FURB164 Verbose method `from_float` in `Fraction` construction
furb164.py:4:7: FURB164 Verbose method `from_decimal` in `Fraction` construction
furb164.py:5:7: FURB164 Verbose method `from_decimal` in `Fraction` construction
furb164.py:6:7: FURB164 Verbose method `from_decimal` in `Fraction` construction
$ ruff --isolated check furb164.py --select FURB164 --preview --unsafe-fixes --fix
Found 4 errors (4 fixed, 0 remaining).
$ cat furb164.py
from decimal import Decimal
from fractions import Fraction
print(Fraction(4.2))
print(Fraction(4))
print(Fraction(Decimal("4.2")))
print(Fraction(Decimal("4.2")))
$ python furb164.py
4728779608739021/1125899906842624
4
21/5
21/5
Version
ruff 0.14.3 (8737a2d 2025-10-30)
Summary
Some fixes of
unnecessary-from-float(FURB164) are marked unsafe but are actually safe: when the argument is specified as a keyword argument but would otherwise be marked safe, and when the argument toFraction.from_decimalis aDecimal. Example:Version
ruff 0.14.3 (8737a2d 2025-10-30)