GeezerVison is showing github.com — gh-142108: Document Decimal formatting behavior differences by Yashp002 · Pull Request #142117 · python/cpython
Conversation
Yashp002
commented
Nov 30, 2025
•
edited by github-actions
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
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/
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this 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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this 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).
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
.. c:function:: PyObject* PyDescr_NewMember(PyTypeObject *type, struct PyMemberDef *meth)
|
|
|
|
|
|
|
|
|
.. c:var:: PyTypeObject PyMemberDescr_Type
|
There was a problem hiding this comment.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Comment on lines
+637
to
+638
|
|
* When using ``__format__`` (f-strings, ``format()``, ``str.format()``),
|
|
|
Decimal formats with maximum precision only when precision is **omitted**
|
There was a problem hiding this comment.
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__().
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- This note not belongs to this section, it's about printf-like formatting.
- 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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
ZeroIntensity
Awaiting requested review from ZeroIntensity
ZeroIntensity will be requested when the pull request is marked ready for review
ZeroIntensity is a code owner
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|