Skip to content

gh-157290: Add support for %Nf to datetime.str{f,p}time() - #157704

Open
StanFromIreland wants to merge 3 commits into
python:mainfrom
StanFromIreland:nf-simple
Open

StanFromIreland wants to merge 3 commits into
python:mainfrom
StanFromIreland:nf-simple

Conversation

@StanFromIreland

@StanFromIreland StanFromIreland commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

This is a slightly simpler approach than the one proposed in #157291. It drops the per-N replacement cache (the existing %f string is sliced instead. I haven't benchmarked it, but I doubt it saves much given it's just an sprintf) and the new ValueError for %7f to %9f, which is inconsistent, since %10f and %.3f (which Rust's chrono supports) still fall through. It also tidies the tests a little.

Co-authored-by: Karoline Pauls <code@karolinepauls.com>
@read-the-docs-community

read-the-docs-community Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34855177 | 📁 Comparing 2f004f7 against main (5539c2a)

  🔍 Preview build  

46 files changed · + 1 added · ± 45 modified

+ Added

± Modified

Comment thread Lib/_pydatetime.py Outdated
Comment thread Modules/_datetimemodule.c Outdated
Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Sep 30, 2026
@StanFromIreland

Copy link
Copy Markdown
Member Author

Thanks Victor, I applied your suggestions!

@vstinner vstinner 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.

LGTM

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

Labels

awaiting merge type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants