Skip to content

Commit 94fc781

Browse files
authored
Defer fractions.Fraction import to save 5ms (#201)
2 parents 74dcc60 + 99c196e commit 94fc781

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/humanize/number.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import math
66
import re
77
import sys
8-
from fractions import Fraction
98
from typing import TYPE_CHECKING
109

1110
from .i18n import _gettext as _
@@ -359,6 +358,8 @@ def fractional(value: NumberOrString) -> str:
359358
return _format_not_finite(number)
360359
except (TypeError, ValueError):
361360
return str(value)
361+
from fractions import Fraction
362+
362363
whole_number = int(number)
363364
frac = Fraction(number - whole_number).limit_denominator(1000)
364365
numerator = frac.numerator

0 commit comments

Comments
 (0)