intword: values between 10^36 and a googol format as huge decillion counts, and rounding to the next unit does not carry
還沒有人認領這個 Issue。
評估
研究方向
從報告中提到的 number.py 變更開始,並使用 Python 3.11 重現邊界範例。向 maintainers 確認該缺口應回退到 str(value),還是在 googol 邊界繼續處理,然後為選定的行為新增回歸測試。當接近 10^100 的值不再產生巨大的 decillion 計數,且捨入遵循議定的規則時,即表示完成。
由索引模型根據 Issue 內容生成。
描述
What happened
intword handles values up to 1000 decillion (10^36) and exactly a googol
(10^100) well, but everything in between formats as an enormous decillion
count:
>>> import humanize
>>> humanize.intword(10**100)
'1.0 googol'
>>> humanize.intword(10**100 - 10**93)
'9999999000000000610151082626636586748864734715312950532670947852288.0 decillion'
>>> humanize.intword(10**50)
'100000000000000000.0 decillion'
A 67 digit unit count defeats the purpose of a human readable number, and
a value just below a googol that rounds up to it never carries to
"1.0 googol".
Verified on humanize 4.16.0 (published wheel) and on current main
(c3a124c), Python 3.11.
Why this looks like a bug rather than a choice
This is the same class of boundary behavior that #328 recently fixed for
metric() (carry to the next SI prefix when rounding reaches 1000). The
powers list jumps from decillion (10^33) to googol (10^100), and the
selection loop picks decillion for anything under a googol, no matter how
large the resulting count is. Values above the largest power already fall
back to str(value), which suggests the intended behavior for
"no reasonable unit" is the plain number, not a unit with a 67 digit
multiplier.
Expected
One of the following, whichever matches the project's intent:
- Values whose formatted count reaches 1000 of a unit with no adjacent
next power fall back tostr(value)(consistent with the existing
above-maximum behavior), and values that round up to exactly the next
power carry to it ("1.0 googol"), consistent with #328's carry rule. - Or simply fall back to
str(value)for the whole gap between 10^36
and 10^100.
I am happy to open a PR with regression tests for the boundary cases once
maintainers confirm which behavior is intended.
How this was found
An automated review gate proposed edge case tests for the recent number.py
changes (the #328 carry fix among them) and executed them against the
code; the "carry just below the next unit" test failed with the output
above. The failing test and its observed output are reproducible by hand
as shown.
- 主要語言
- Python
- 星號
- 757
- 分支
- 148
- 平均合併
- 6 天 1 小時
- 30 天內合併 PR
- 12
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python-humanize/humanize 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
python-humanize/humanize#379 ·
-
難度 2/5 1-3 小時 新手友好度 75/100
python-humanize/humanize#366 ·
-
難度 3/5 1-2 天 新手友好度 48/100
python-humanize/humanize#277 · 1 則留言 ·
-
bug
難度 4/5 3-5 天 新手友好度 45/100
python-humanize/humanize#270 · 6 則留言 ·
-
help wanted
難度 4/5 3-5 天 新手友好度 35/100
python-humanize/humanize#263 · 3 個 reaction ·
查看 python-humanize/humanize 的全部 Issue
相似的 Issue
-
documentation help wanted
難度 2/5 1-3 小時 新手友好度 90/100
-
難度 2/5 1-3 小時 新手友好度 90/100
simonw/sqlite-utils#872 ·
-
難度 2/5 1-3 小時 新手友好度 88/100
-
難度 2/5 1-3 小時 新手友好度 82/100
-
難度 2/5 1-3 小時 新手友好度 78/100