Repository navigation
, works with Decimal() against the doc of **Format Specification Mini-Language** #136636
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Jul 13, 2025 I'm not sure I understand the first issue namely with
,. The grammar says:grouping ::= "," | "_"
So
,is supported as you observed (both for integer and floating-point presentations). As for_, do you mean that it doesn't work for any of the floating-point presentation types? I don't have access to a 3.13+ installation so I can't check. Also, in the future, please check the bugs against the stable versions, and not those that are security-only.cc @skirpichev
- addedpendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
on Jul 13, 2025 This is certainly not a bug. The Decimal formatting is documented on the quoted page, as it says that available presentation types for floats and Decimals are same.
On the other hand, the Decimal is not a builtin type, maybe it's better to document it's formatting separately, as for Fractions, in the module page. (Right now it even has no examples of formatted output, see #128698.)
- added and removedpendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
on Jul 14, 2025 The "floating-point presentation types" are the implicit or explict f,F,g,G, not the object type. I don't see why you are getting the error messages. Maybe a fixed bug. In installed 3.14.0b4 and main:
>>> '{:_.20}'.format(d) '123_456.123456' >>> '"{:_.20}"'.format(d) '"123_456.123456"'Same with f-strings.
EDIT: Mismatches between presentation type and object type are ValueErrors.
>>> '{:_.20}'.format('453455') Traceback (most recent call last): File "<python-input-4>", line 1, in <module> '{:_.20}'.format('453455') ~~~~~~~~~~~~~~~~^^^^^^^^^^ ValueError: Cannot specify '_' with 's'.Ah, I thought my patch was backported: #132155
Backport for 3.13: #136649
3.12 is security-only, so we can't do anything here.
- addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directoryextension-modulesC modules in the Modules dirC modules in the Modules dir
on Jul 14, 2025 Backport has been merged, should this not be classified as a duplicate of its issue?
Yes, it would be a duplicate now.
Bug report
Bug description:
The doc of Format Specification Mini-Language doesn't say that
,works with Decimal() as shown below:But
,works withDecimal()against the doc as shown below:In addition, the doc doesn't say that
_works withDecimal()as shown below:So,
_doesn't work withDecimal()as the doc doesn't say so as shown below:CPython versions tested on:
3.12
Operating systems tested on:
Windows