Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/humanize/filesize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _

Expand Down Expand Up @@ -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
Expand Down
Loading