GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-142108: Document Decimal formatting behavior differences by Yashp002 · Pull Request #142117 · python/cpython

Conversation

@Yashp002

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

Uh oh!

There was an error while loading. Please reload this page.

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

  • Issue: Improve printf-style formatting docs for non-built-in types #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.

All reactions
Yashp002 added 5 commits November 20, 2025 23:49
@Yashp002
pythongh-141004: Document descriptor and dict proxy type objects
874fc1c
@Yashp002
Fixing git errors
cae9245
@Yashp002
Lint fixes
69ad04d
@Yashp002
desc and dict.rst changes
d38b637
@Yashp002
lint fixes
b71c072
@bedevere-app bedevere-app Bot added awaiting review docs Documentation in the Doc dir skip news labels Nov 30, 2025
@github-project-automation github-project-automation Bot added this to Docs PRs Nov 30, 2025
@github-project-automation github-project-automation Bot moved this to Todo in Docs PRs Nov 30, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Nov 30, 2025
Improve printf-style formatting docs for non-built-in types #142108
Open
@Yashp002
changes to decimal doc
1199df7
@Yashp002
Yashp002 force-pushed the formatdoc branch from bec8d83 to 1199df7 Compare November 30, 2025 18:47
StanFromIreland
StanFromIreland requested changes Nov 30, 2025
View reviewed changes

@StanFromIreland StanFromIreland left a comment

Copy link
Copy Markdown
Member

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.

All reactions
@bedevere-app bedevere-app Bot added awaiting core review and removed awaiting review labels Nov 30, 2025
skirpichev
skirpichev requested changes Nov 30, 2025
View reviewed changes

@skirpichev skirpichev left a comment

Copy link
Copy Markdown
Member

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.

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


.. c:var:: PyTypeObject PyMemberDescr_Type

@skirpichev skirpichev Nov 30, 2025

Copy link
Copy Markdown
Member

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.

All reactions
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**

@skirpichev skirpichev Nov 30, 2025

Copy link
Copy Markdown
Member

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.

All reactions
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

@skirpichev skirpichev Nov 30, 2025

Copy link
Copy Markdown
Member

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.

  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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@skirpichev
skirpichev marked this pull request as draft November 30, 2025 21:16
@bedevere-app bedevere-app Bot removed the awaiting core review label Nov 30, 2025
@Yashp002

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Yashp002 Yashp002 closed this Dec 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@skirpichev skirpichev skirpichev requested changes
@StanFromIreland StanFromIreland StanFromIreland requested changes
@ZeroIntensity 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

Labels

docs Documentation in the Doc dir skip news

Projects

Docs PRs
Status: Todo

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

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

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@Yashp002 @skirpichev @StanFromIreland
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.