From d6913190a3097cd7bf4f22a4e7e45a9599383c37 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Tue, 8 Sep 2026 15:25:03 +0300 Subject: [PATCH] Defer importing math --- src/humanize/filesize.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/humanize/filesize.py b/src/humanize/filesize.py index fb675fdc..063affe0 100644 --- a/src/humanize/filesize.py +++ b/src/humanize/filesize.py @@ -2,9 +2,7 @@ from __future__ import annotations -__lazy_modules__ = {"humanize.i18n", "math"} - -from math import log +__lazy_modules__ = {"humanize.i18n"} from humanize.i18n import _gettext as _ @@ -98,6 +96,8 @@ def naturalsize( if abs_bytes < base: return f"{int(bytes_)}B" if gnu else _("%d Bytes") % int(bytes_) + from math import log + exp = int(min(log(abs_bytes, base), len(suffix))) # The suffix is chosen from the unrounded byte count, but `format` rounds the # mantissa afterward; rounding can push it up to `base` (e.g. 999999 is