Skip to content

Commit

Permalink
Defer other imports for faster overall import
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Feb 12, 2025
1 parent 9e0c073 commit 147cbbc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/humanize/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

import math
import re

from .i18n import _gettext as _
from .i18n import _ngettext, decimal_separator, thousands_separator
Expand Down Expand Up @@ -166,6 +165,8 @@ def intcomma(value: NumberOrString, ndigits: int | None = None) -> str:
else:
orig = str(value)
orig = orig.replace(".", decimal_sep)
import re

while True:
new = re.sub(r"^(-?\d+)(\d{3})", rf"\g<1>{thousands_sep}\g<2>", orig)
if orig == new:
Expand Down Expand Up @@ -430,6 +431,8 @@ def scientific(value: NumberOrString, precision: int = 2) -> str:
n = fmt.format(value)
part1, part2 = n.split("e")
# Remove redundant leading '+' or '0's (preserving the last '0' for 10⁰).
import re

part2 = re.sub(r"^\+?(\-?)0*(.+)$", r"\1\2", part2)

new_part2 = []
Expand Down
3 changes: 1 addition & 2 deletions src/humanize/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from __future__ import annotations

import collections.abc
import datetime as dt
import math
from enum import Enum
Expand Down Expand Up @@ -328,7 +327,7 @@ def _quotient_and_remainder(
divisor: float,
unit: Unit,
minimum_unit: Unit,
suppress: collections.abc.Iterable[Unit],
suppress: Iterable[Unit],
) -> tuple[float, float]:
"""Divide `value` by `divisor` returning the quotient and remainder.
Expand Down

0 comments on commit 147cbbc

Please sign in to comment.