Skip to content

PEP 786: Precision and Modulo-Precision Flag format specifiers for integer fields#4416

Open
jb2170 wants to merge 22 commits intopython:mainfrom
jb2170:pep-786-precision
Open

PEP 786: Precision and Modulo-Precision Flag format specifiers for integer fields#4416
jb2170 wants to merge 22 commits intopython:mainfrom
jb2170:pep-786-precision

Conversation

@jb2170
Copy link

@jb2170 jb2170 commented May 8, 2025

New rebased PR with the correct branch name to avoid confusion (786 not 791).

Thank you Alyssa for sponsoring this!

Relevant discussions, issues, PRs linked

Basic requirements (all PEP Types)

  • Read and followed PEP 1 & PEP 12
  • File created from the latest PEP template
  • PEP has next available number, & set in filename (pep-NNNN.rst), PR title (PEP 123: <Title of PEP>) and PEP header
  • Title clearly, accurately and concisely describes the content in 79 characters or less
  • Core dev/PEP editor listed as Author or Sponsor, and formally confirmed their approval: @ncoghlan
  • Author, Status (Draft), Type and Created headers filled out correctly
  • PEP-Delegate, Topic, Requires and Replaces headers completed if appropriate: Is a PEP-Delegate required?
  • Required sections included
    • Abstract (first section)
    • Copyright (last section; exact wording from template required)
  • Code is well-formatted (PEP 7/PEP 8) and is in code blocks, with the right lexer names if non-Python: everything but 80-column line length, so as to avoid tedious re-aligning during this draft stage
  • PEP builds with no warnings, pre-commit checks pass and content displays as intended in the rendered HTML
  • Authors/sponsor added to .github/CODEOWNERS for the PEP

Standards Track requirements

  • PEP topic discussed in a suitable venue with general agreement that a PEP is appropriate
  • Suggested sections included (unless not applicable)
    • Motivation: included in Rationale
    • Rationale
    • Specification: Abstract is RFC 2119 style
    • Backwards Compatibility
    • Security Implications: not needed?
    • How to Teach This: Examples And Teaching section
    • Reference Implementation
    • Rejected Ideas
    • Open Issues: None so far
  • Python-Version set to valid (pre-beta) future Python version, if relevant
  • Any project stated in the PEP as supporting/endorsing/benefiting from the PEP formally confirmed such: none
  • Right before or after initial merging, PEP discussion thread created and linked to in Discussions-To and Post-History

📚 Documentation preview 📚: https://pep-previews--4416.org.readthedocs.build/pep-0786/

@jb2170 jb2170 requested a review from a team as a code owner May 8, 2025 01:09
@AA-Turner AA-Turner added the new-pep A new draft PEP submitted for initial review label May 8, 2025
@AA-Turner AA-Turner requested a review from ncoghlan May 8, 2025 01:19
Copy link
Member

@AA-Turner AA-Turner left a comment

Choose a reason for hiding this comment

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

I haven't read the content of the PEP yet, but a few notes:

jb2170 added 2 commits May 8, 2025 03:29
It's better to give the formatspec one canonical ordering than permit an
overly liberal rearrangeability.

If commutativity were added, then as well as the messy description required
for the docs for the particular case of `int` data, two people could write
two different format spec that result in the same output and not realise
it or agree, because they've written different things, leading to confusion etc.
jb2170 and others added 6 commits May 16, 2025 07:47
I'll address the other ones in a separate commit(s)

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
I'm the author of this PEP. Sergey and Raymond shouldn't be pestered over it. They are in the appropriate 'Thanks' section.
Copy link
Member

@skirpichev skirpichev left a comment

Choose a reason for hiding this comment

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

Disclaimer: My English, probably, is horrible. Perhaps, it was the reason why this text looks too difficult for me to follow and understand. Anyway, here my 2c as PEP reader.

The PEP text is huge, c.f. PEP 682 (roughly half of this). While it's idea (even with optional extension for 'z' flag) looks damn simple. I think the text win if you address this issue.

Also, you might consider to better follow to standard section meanings. E.g. "Rationale" should describe why particular design decisions were made. While "Motivation" - why we need proposed features at all. "Specification", "Rejected Ideas", etc.

I also suggest to move 'z' flag proposal to the "Open Issues" section. It was very briefly discussed in the ideas thread, not backed by existing feature requests and proposed specification clearly contradicts to the C behavior.

@hugovk
Copy link
Member

hugovk commented Mar 4, 2026

Where are we up to with this PEP?

@jb2170
Copy link
Author

jb2170 commented Mar 7, 2026

All it needs is the reference implementation and it's ready imo.

I got frustrated with skirpichev not understanding the intended modular arithmetic behaviour / two's complement / C integer types wrapping, and so I left this PEP stagnant, but I have thought about it at least once a day for the past several months now!

I'll have a go at the implementation. It's my first time dealing with Python's C code so do double check if I use a Py_INCREF instead of Py_XINCREF etc 😅

@hugovk
Copy link
Member

hugovk commented Mar 7, 2026

OK, good luck! Keep in mind there's two months until the 3.15 feature freeze, so this would need to be merged/discussed/submitted to SC/accepted/implemented before then. But there's always 3.16 after that.

@jb2170
Copy link
Author

jb2170 commented Mar 25, 2026

Reference implementation section added, all set.

The reference implementation itself is at python/cpython#146437

I'll rebase it off of the main branch tomorrow (unless it's easier to read as-is?).

Everything seems ready.

Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

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

@ncoghlan As sponsor, please could you give this a review before we merge and kick off the discussion?

jb2170 and others added 2 commits March 26, 2026 16:43
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-pep A new draft PEP submitted for initial review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants