mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:25:17 +00:00

## Summary <!-- What's the purpose of the change? What does it do, and why? --> Implement FURB164 in the issue #1348. Relevant Refurb docs is here: https://github.com/dosisod/refurb/blob/v2.0.0/docs/checks.md#furb164-no-from-float I've changed the name from `no-from-float` to `verbose-decimal-fraction-construction`. ## Test Plan <!-- How was it tested? --> I've written it in the `FURB164.py`. --------- Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
34 lines
907 B
Python
34 lines
907 B
Python
from decimal import Decimal
|
|
from fractions import Fraction
|
|
import decimal
|
|
import fractions
|
|
|
|
# Errors
|
|
_ = Fraction.from_float(0.1)
|
|
_ = Fraction.from_float(-0.5)
|
|
_ = Fraction.from_float(5.0)
|
|
_ = fractions.Fraction.from_float(4.2)
|
|
_ = Fraction.from_decimal(Decimal("4.2"))
|
|
_ = Fraction.from_decimal(Decimal("-4.2"))
|
|
_ = Fraction.from_decimal(Decimal.from_float(4.2))
|
|
_ = Decimal.from_float(0.1)
|
|
_ = Decimal.from_float(-0.5)
|
|
_ = Decimal.from_float(5.0)
|
|
_ = decimal.Decimal.from_float(4.2)
|
|
_ = Decimal.from_float(float("inf"))
|
|
_ = Decimal.from_float(float("-inf"))
|
|
_ = Decimal.from_float(float("Infinity"))
|
|
_ = Decimal.from_float(float("-Infinity"))
|
|
_ = Decimal.from_float(float("nan"))
|
|
|
|
# OK
|
|
_ = Fraction(0.1)
|
|
_ = Fraction(-0.5)
|
|
_ = Fraction(5.0)
|
|
_ = fractions.Fraction(4.2)
|
|
_ = Fraction(Decimal("4.2"))
|
|
_ = Fraction(Decimal("-4.2"))
|
|
_ = Decimal(0.1)
|
|
_ = Decimal(-0.5)
|
|
_ = Decimal(5.0)
|
|
_ = decimal.Decimal(4.2)
|