FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-142108: Document Decimal formatting behavior differences by Yashp002 · Pull Request #142117 · python/cpython · GitHub

Repository navigation

gh-142108: Document Decimal formatting behavior differences - #142117

Closed
Yashp002 wants to merge 6 commits into
python:mainfrom
Yashp002:formatdoc
Closed

Yashp002 wants to merge 6 commits into
python:mainfrom
Yashp002:formatdoc

Conversation

Yashp002 commented Nov 30, 2025 •
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Contributor

This PR clarifies how Decimal 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 is omitted in f/e/g format types; explicit precision is respected
    • For % formatting: Decimal values are converted to float first, resulting in potential precision loss

Documentation preview: (will be auto-generated)

Fixes #142108


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

StanFromIreland left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

skirpichev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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).

Comment thread Doc/c-api/descriptor.rst
.. c:function:: PyObject* PyDescr_NewMember(PyTypeObject *type, struct PyMemberDef *meth)


.. c:var:: PyTypeObject PyMemberDescr_Type

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Comment thread Doc/library/string.rst
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 thread Doc/library/string.rst
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
  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.

skirpichev marked this pull request as draft November 30, 2025 21:16

Yashp002 commented Dec 1, 2025

Copy link
Copy Markdown
Contributor Author

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.

Yashp002 closed this Dec 1, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Improve printf-style formatting docs for non-built-in types

3 participants


Back | FazBrowse Home | New Git URL