GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Incompatible (wrt floats) processing of alignment and '0' flag in Fraction's formatting · Issue #130716 · python/cpython Closed as duplicate Closed as duplicate Copy link Labels docsDocumentation in the Doc dirDocumentation in the Doc dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error DescriptionBug reportBug description:>>> x = Fraction(1, 3) >>> f"{x:_>010f}" Traceback (most recent call last): File "<python-input-2>", line 1, in <module> f"{x:_>010f}" ^^^^^^^^^^ File "/home/sk/src/cpython/Lib/fractions.py", line 600, in __format__ raise ValueError( ...<2 lines>... ) ValueError: Invalid format specifier '_>010f' for object of type 'Fraction' >>> f"{float(x):_>010f}" '__0.333333' While not being documented, this behavior is intentional (see #100161): "The Fraction formatter is also stricter about combining these two things: it's not permitted to use both the '0' flag and explicit alignment, on the basis that we should refuse the temptation to guess in the face of ambiguity." In floats case, "0" flag is just ignored if the fill character (and, thus, alignment) already specified. Maybe it's not a bad idea to use Fraction's behavior for floats too, i.e. deprecate this silent resolution of ambiguity. Or just document this discrepancy. Decimal's behave here like Fraction's: >>> f"{Decimal(1.25):_>010f}" Traceback (most recent call last): File "<python-input-5>", line 1, in <module> f"{Decimal(1.25):_>010f}" ^^^^^^^^^^^^^^^^^^^^^^ ValueError: invalid format string CPython versions tested on:CPython main branch Operating systems tested on:No response Activity
MetadataMetadataAssigneesLabelsdocsDocumentation in the Doc dirDocumentation in the Doc dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error Projects
MilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |