Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-130662: accept leading zeros in precision/width for Fraction's formatting#130663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
skirpichev wants to merge2 commits intopython:main
base:main
Choose a base branch
Loading
fromskirpichev:fix-fmt-fractions/130662

Conversation

skirpichev
Copy link
Contributor

@skirpichevskirpichev commentedFeb 28, 2025
edited by bedevere-appbot
Loading

@skirpichev
Copy link
ContributorAuthor

CC@ericvsmith per experts index

Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM.

I have some minor suggestions for tests.

Copy link
Member

@gvanrossumgvanrossum left a comment

Choose a reason for 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/3f"{x:_>010f}"# '__3.140000', ignores the zero-padx=Fraction(1,3)Traceback (mostrecentcalllast):File"<python-input-4>",line1,in<module>f"{x:_>010f}"^^^^^^^^^^File"/Users/guido/cpython/Lib/fractions.py",line600,in__format__raiseValueError(    ...<2lines>...    )ValueError:Invalidformatspecifier'_>010f'forobjectof 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?

@skirpichev
Copy link
ContributorAuthor

skirpichev commentedMar 1, 2025
edited
Loading

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

@gvanrossum
Copy link
Member

As happens occasionally, the docs are out of sync with the implementation, and we should respond by updating the docs, not the code. IMO.

@skirpichev
Copy link
ContributorAuthor

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.

@gvanrossum
Copy link
Member

Okay, I will leave it to more active core devs to sort out.

@skirpichev
Copy link
ContributorAuthor

Alternative pr:#130717

Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@skirpichevskirpichev changed the titlegh-130662: make Fraction's formatting more compatible wrt float'sgh-130662: accept leading zeros in precision/width for Fraction's formattingApr 15, 2025
@skirpichevskirpichev added the 3.14bugs and security fixes labelApr 28, 2025
@skirpichevskirpichev added needs backport to 3.14bugs and security fixes and removed 3.14bugs and security fixes labelsMay 8, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@gvanrossumgvanrossumgvanrossum left review comments

@serhiy-storchakaserhiy-storchakaserhiy-storchaka approved these changes

@vstinnervstinnervstinner approved these changes

Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@skirpichev@gvanrossum@vstinner@serhiy-storchaka

[8]ページ先頭

©2009-2025 Movatter.jp