Undocumented handling of thousands separator for floats and differences wrt Decimal
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Bug description:
In docs we have:
The ',' option signals the use of a comma for a thousands separator for floating-point presentation types and for integer presentation type 'd'. For other presentation types, this option is an error. For a locale aware separator, use the 'n' integer presentation type instead.
The '_' option signals the use of an underscore for a thousands separator for floating-point presentation types and for integer presentation type 'd'. For integer presentation types 'b', 'o', 'x', and 'X', underscores will be inserted every 4 digits. For other presentation types, specifying this option is an error.
But this doesn't specify how separators are inserted for customized alignment, consider:
>>> format(0.0, '>020_f')
'0000000000000.000000'
>>> format(0.0, '<020_f')
'0.000000000000000000'
>>> format(0.0, '=020_f')
'0_000_000_000.000000'
>>> format(0.0, '^020_f')
'0000000.000000000000'
Probably it's obvious, that separators might be inserted only in case of 0-padding and = alignment, though maybe this should be mentioned explicitly.
Note also that neither from above supported by Decimal/Fraction, e.g.:
>>> format(Decimal(0.0), '=020_f')
Traceback (most recent call last):
File "<python-input-13>", line 1, in <module>
format(Decimal(0.0), '=020_f')
~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid format string
>>> format(Fraction(0.0), '=020_f')
' 0.000000'
>>> format(float(Fraction(0.0)), '=020_f')
'0_000_000_000.000000'
BTW, the rationale for Fraction's behavior (see https://github.com/python/cpython/pull/100161) is "no special-casing of the particular '0=' fill-character/alignment combination", which is rather weak, IMO.
Either this should be fixed (preferred) or documented.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
- gh-131030
- gh-131067
- gh-132155
- gh-136241
- gh-136242
- gh-136649
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず format specification mini-language のドキュメントを読み、issue にある float、Decimal、Fraction の例を再現します。リンクされている PR を確認し、すでに進行中の作業を理解します。セパレーターとアラインメントの挙動を一貫して解決するか、確認された規則を文書化できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- documentation
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100