| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
naturalsize(10**309) raises OverflowError because float(value) is called unconditionally and int→float conversion overflows for very large integers. Fix: wrap float(value) in try/except (ValueError, OverflowError) and re-raise with a clear message. Reproducer: >>> import humanize >>> humanize.naturalsize(10**309) OverflowError: int too large to convert to float
| Back | FazBrowse Home | New Git URL |
Problem
naturalsize() calls float(value) unconditionally, which raises OverflowError for very large integers:
It also raises a raw ValueError from float() for non-numeric strings, with a confusing message.
Fix
Wrap float(value) in try/except (ValueError, OverflowError) and re-raise with a clear message indicating the argument type.
After fix