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
7 changes: 6 additions & 1 deletion src/humanize/filesize.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ def naturalsize(
suffix = suffixes["decimal"]

base = 1024 if (gnu or binary) else 1000
bytes_ = float(value)
try:
bytes_ = float(value)
except (ValueError, OverflowError) as exc:
raise ValueError(
f"naturalsize() argument must be a number, not {type(value).__name__!r}"
) from exc
abs_bytes = abs(bytes_)

if abs_bytes == 1 and not gnu:
Expand Down