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-142108: Document Decimal formatting behavior differences#142117

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

Closed
Yashp002 wants to merge6 commits intopython:mainfromYashp002:formatdoc

Conversation

@Yashp002
Copy link
Contributor

@Yashp002Yashp002 commentedNov 30, 2025
edited by github-actionsbot
Loading

This PR clarifies howDecimal behaves differently when formatted using__format__ (f-strings,format(),str.format()) versus% formatting (old-style string formatting).

Changes:

  • Added a note in the Format Specification Mini-Language section explaining:
    • For__format__: Decimal uses maximum precision only when precision isomitted in f/e/g format types; explicit precision is respected
    • For% formatting: Decimal values are converted tofloat first, resulting in potential precision loss

Documentation preview: (will be auto-generated)

Fixes#142108


📚 Documentation preview 📚:https://cpython-previews--142117.org.readthedocs.build/

Copy link
Member

@StanFromIrelandStanFromIreland left a comment

Choose a reason for hiding this comment

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

You have multiple different changes mixed together, please split it out.

Copy link
Contributor

@skirpichevskirpichev left a comment

Choose a reason for hiding this comment

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

I'll mark this a draft. Sorry, but current approach seems unacceptable for me.

PS: Please also don't alter commit history in any way (force-pushes, etc).

..c:function:: PyObject*PyDescr_NewMember(PyTypeObject *type, struct PyMemberDef *meth)
..c:var:: PyTypeObject PyMemberDescr_Type
Copy link
Contributor

Choose a reason for hiding this comment

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

Changes in Doc/c-api/ are not related to this pr, please revert.

Comment on lines +637 to +638
* When using ``__format__`` (f-strings, ``format()``, ``str.format()``),
Decimal formats with maximum precision only when precision is **omitted**
Copy link
Contributor

Choose a reason for hiding this comment

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

This is already documented, please revert. Also, the whole section of documentation is about string formatting, it's pointless to say that you are using__format__().

Comment on lines +642 to +643
* When using ``%`` formatting (old-style string formatting with the ``%`` operator),
Decimal values are first converted to:class:`float`, which may result in
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. This note not belongs to this section, it's about printf-like formatting.
  2. In the issue thread it was explained, that there is nothing special about Decimal's here. If we have to document something, it should be about behavior of printf-like formatting for non-builtin types.

@skirpichevskirpichev marked this pull request as draftNovember 30, 2025 21:16
@Yashp002
Copy link
ContributorAuthor

Apologies for the confusion—I had an out-of-sync branch that mixed commits from multiple PRs.

After reviewing the feedback, I realize:

  • The note placement was incorrect (this section is about printf-like formatting)
  • This behavior may already be documented elsewhere

Closing this PR. I'll discuss on the issue thread whether any documentation changes are still needed before opening a fresh PR.

Thanks for the review.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@skirpichevskirpichevskirpichev requested changes

@StanFromIrelandStanFromIrelandStanFromIreland requested changes

Assignees

No one assigned

Labels

docsDocumentation in the Doc dirskip news

Projects

Status: Todo

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Improveprintf-style formatting docs for non-built-in types

3 participants

@Yashp002@skirpichev@StanFromIreland

[8]ページ先頭

©2009-2025 Movatter.jp