Skip to content

Commit 147cbbc

Browse files
committed
Defer other imports for faster overall import
1 parent 9e0c073 commit 147cbbc

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/humanize/number.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
import math
6-
import re
76

87
from .i18n import _gettext as _
98
from .i18n import _ngettext, decimal_separator, thousands_separator
@@ -166,6 +165,8 @@ def intcomma(value: NumberOrString, ndigits: int | None = None) -> str:
166165
else:
167166
orig = str(value)
168167
orig = orig.replace(".", decimal_sep)
168+
import re
169+
169170
while True:
170171
new = re.sub(r"^(-?\d+)(\d{3})", rf"\g<1>{thousands_sep}\g<2>", orig)
171172
if orig == new:
@@ -430,6 +431,8 @@ def scientific(value: NumberOrString, precision: int = 2) -> str:
430431
n = fmt.format(value)
431432
part1, part2 = n.split("e")
432433
# Remove redundant leading '+' or '0's (preserving the last '0' for 10⁰).
434+
import re
435+
433436
part2 = re.sub(r"^\+?(\-?)0*(.+)$", r"\1\2", part2)
434437

435438
new_part2 = []

src/humanize/time.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from __future__ import annotations
77

8-
import collections.abc
98
import datetime as dt
109
import math
1110
from enum import Enum
@@ -328,7 +327,7 @@ def _quotient_and_remainder(
328327
divisor: float,
329328
unit: Unit,
330329
minimum_unit: Unit,
331-
suppress: collections.abc.Iterable[Unit],
330+
suppress: Iterable[Unit],
332331
) -> tuple[float, float]:
333332
"""Divide `value` by `divisor` returning the quotient and remainder.
334333

0 commit comments

Comments
 (0)