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 — gh-130662: accept leading zeros in precision/width for Fraction's formatting by skirpichev · Pull Request #130663 · python/cpython Conversation
|
|
CC @ericvsmith per experts index |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
I have some minor suggestions for tests.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Note that there's another inconsistency between float and Fraction.
x = 1/3 f"{x:_>010f}" # '__3.140000', ignores the zero-pad x = Fraction(1, 3) Traceback (most recent call last): File "<python-input-4>", line 1, in <module> f"{x:_>010f}" ^^^^^^^^^^ File "/Users/guido/cpython/Lib/fractions.py", line 600, in __format__ raise ValueError( ...<2 lines>... ) ValueError: Invalid format specifier '_>010f' for object of type 'Fraction'
So we still fail the goal of Fraction supporting everything that float does. Since Fraction actually is more strict (which is the way of the future) aren't we fixing this the wrong way?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Here is implementation pr, for context: #100161 The ValueError raised in case both alignment (and the fill character) and zero padding are specified on the ground "refuse the temptation to guess". In principle, it's not hard to reproduce float's behavior (zero padding is ignored if the fill character is specified). Though, maybe it's better to align this with the Fraction instead. Probably, it's a separate issue. Edit: #130716 Few another incompatibilities: #130664 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
As happens occasionally, the docs are out of sync with the implementation, and we should respond by updating the docs, not the code. IMO. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The problem is that the stdlib has several beasts (Decimal and Fraction), that have slightly different implementations of new-style formatting. IMO, documenting all these differences will make documentation much less readable. Also, it's less obvious to which convention should follow external modules, like the mpmath or the gmpy2. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Okay, I will leave it to more active core devs to sort out. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Alternative pr: #130717 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I agree with @serhiy-storchaka: #130662 (comment)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Bénédikt Tran <[email protected]>
|
Thanks @skirpichev for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…'s formatting (pythonGH-130663) (cherry picked from commit 5bc2d99) Co-authored-by: Sergey B Kirpichev <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
|
GH-135026 is a backport of this pull request to the 3.14 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Merged, thank you.
I disagree: we should not backport this change to stable branches. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Wasn't it a fix for something we introduced in 3.14? @skirpichev |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
No, Python 3.13 has the same behavior for example. It was "always" like that. @skirpichev proposed to have the behavior for all types: float, Fraction, Decimal. Before, only float accepted leading zeros. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Why not? It's a bug, isn't? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
From my point of view, it's a new feature and existing projects may rely on the current (Python 3.14) behavior. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
How?! The issue is about formatting stdlib types (Fractions and Decimals, in a separate pr). Should external projects use current formatting specification mini-language or use more strict rules? This was coming from mpmath/mpmath#915. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
From my point of view, this is a borderline between a minor feature and an unsignificant bug fix which we may not want to backport. So maybe to 3.14 only? The solved problem is rather scholastic. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @skirpichev for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…'s formatting (pythonGH-130663) (cherry picked from commit 5bc2d99) Co-authored-by: Sergey B Kirpichev <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
|
GH-136361 is a backport of this pull request to the 3.14 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…n's formatting (GH-130663) (#136361) Co-authored-by: Sergey B Kirpichev <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
…'s formatting (python#130663) Co-authored-by: Bénédikt Tran <[email protected]>
…'s formatting (python#130663) Co-authored-by: Bénédikt Tran <[email protected]>
…'s formatting (python#130663) Co-authored-by: Bénédikt Tran <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.