| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
naturalsize() chooses the suffix from the unrounded byte count via
int(min(log(abs_bytes, base), ...)), then rounds the mantissa with the
format string afterward. When rounding pushes the mantissa up to the base,
the already-chosen suffix is left stale:
>>> naturalsize(999999)
'1000.0 kB' # expected '1.0 MB'
>>> naturalsize(999999999)
'1000.0 MB' # expected '1.0 GB'
>>> naturalsize(1024 ** 2 - 1, binary=True)
'1024.0 KiB' # expected '1.0 MiB'
This is distinct from the ZB->YB top-boundary fix in python-humanize#206 (which added
larger suffixes but did not touch the rounding) and from the metric() fix
in python-humanize#328 (a different function). Here the rollover happens at every small
unit too.
Fix: after rounding, if the mantissa has reached the base and a larger
suffix is available, step up one suffix. Added regression cases to
test_naturalsize (they fail before this change, pass after); all existing
assertions and documented examples are unchanged.
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #329 +/- ##
=======================================
Coverage 99.55% 99.55%
=======================================
Files 12 12
Lines 900 902 +2
=======================================
+ Hits 896 898 +2
Misses 4 4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness.
|
Sorry, something went wrong.
|
Thanks! |
Sorry, something went wrong.
…I integrity gate Three new provenance-pinned rules, each distilled from a *merged* gift-PR fleet fix (stronger provenance than the open-PR rules in AB003-005): - AB006 radix-from-source-not-override [high/default] skorokithakis/shortuuid#115 (merged) — len/radix derived from the original parameter after an override parameter is established as the source of truth; alpha_len = len(alphabet) instead of len(alphabet_index). - AB007 log-exp-rounded-mantissa-no-carry [medium/pedantic] python-humanize/humanize#329 (merged) — magnitude exponent chosen from the unrounded value, then the mantissa formatted with rounding; no carry-guard when rounding rolls the mantissa to the base ('1000.0 kB'). - AB008 magnitude-bin-inclusive-boundary-break [medium/pedantic] mahmoud/boltons#403 (merged) — consecutive-bin loop breaks on '<=' against the next bin's lower bound; bytes2human(1024) -> '1024B'. Corpus now: 8 rules, 5 merged-PR-backed (AB001/AB002/AB006/AB007/AB008), 3 open-PR (AB003/AB004/AB005). All 8 upstream URLs verified against the GitHub API (state + merged flag) at commit time. CI hardening (.github/workflows/ci.yml): - New 'Corpus integrity gate' step runs the corpus-size, URL-format + generator-attribution, and merged>=open invariant tests verbosely as a named gate (not just under the general test step). - Added pedantic-tier self-scan of own source (both tiers must stay clean). - Integrity test strengthened: URL must match ^https://github.com/[^/]+/[^/]+/pull/\d+$; generator field checked against an 11-name denylist (copilot/chatgpt/gpt/claude/gemini/cursor/ codex/codewhisperer/deepseek/llama/mistral). 31 tests green (20 -> 31). Self-scan clean at both default and pedantic tiers. Version bumped to 0.2.0. Optional ast-grep multi-lang port (goal #3) deferred: ast-grep binary is not installed locally, and shipping an unverified .sgy would violate the build-honesty discipline that is the product's premise. Co-Authored-By: claude-flow <ruv@ruv.net>
| Back | FazBrowse Home | New Git URL |
Problem
naturalsize() picks the suffix from the unrounded byte count (exp = int(min(log(abs_bytes, base), ...))), then rounds the mantissa with the format string afterward. When rounding pushes the mantissa up to the base, the already-chosen suffix is left stale:
999999 bytes is 999.999 kB; "%.1f" rounds that to 1000.0, but the suffix was already fixed at kB, so the output reads 1000.0 kB instead of 1.0 MB. This happens at every decimal, binary, and GNU boundary.
This is distinct from the two related changes already in the repo:
Fix
After rounding, if the mantissa has reached the base (1000 decimal / 1024 binary) and a larger suffix is available, step up one suffix. Values already at the largest suffix (QB/QiB) are unaffected (e.g. the documented naturalsize(10**34 * 3) → '30000.0 QB' still holds), as are all values that don't round across a boundary.
Tests
Added regression assertions to test_naturalsize covering decimal, binary, and GNU boundaries. They fail on the current code and pass with this change; every existing assertion and documented example is unchanged (70 → 76 passing).