Skip to content
Closed
Changes from 1 commit
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
Comment on lines +90 to +95

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't add support, just re-raises an OverflowError as ValueError with an incorrect error:

>>> humanize.naturalsize(10**309)
ValueError: naturalsize() argument must be a number, not 'int'

An int is a number.

>>> humanize.naturalsize("abc")
ValueError: naturalsize() argument must be a number, not 'str'

Numeric strings are documented as an acceptable input.

abs_bytes = abs(bytes_)

if abs_bytes == 1 and not gnu:
Expand Down