From 99c196e8ad10b148b66cfa612bccfdcdb8b5d346 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Mon, 9 Sep 2024 21:28:16 +0300 Subject: [PATCH] Defer fractions.Fraction import --- src/humanize/number.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/humanize/number.py b/src/humanize/number.py index 7bf7c55..3f42f64 100644 --- a/src/humanize/number.py +++ b/src/humanize/number.py @@ -5,7 +5,6 @@ import math import re import sys -from fractions import Fraction from typing import TYPE_CHECKING from .i18n import _gettext as _ @@ -359,6 +358,8 @@ def fractional(value: NumberOrString) -> str: return _format_not_finite(number) except (TypeError, ValueError): return str(value) + from fractions import Fraction + whole_number = int(number) frac = Fraction(number - whole_number).limit_denominator(1000) numerator = frac.numerator