Skip to content

gh-140715: Add %t and %n format codes support to strptime()#144896

Open
jyalim wants to merge 26 commits intopython:mainfrom
jyalim:fix-issue-140715--t
Open

gh-140715: Add %t and %n format codes support to strptime()#144896
jyalim wants to merge 26 commits intopython:mainfrom
jyalim:fix-issue-140715--t

Conversation

@jyalim
Copy link
Contributor

@jyalim jyalim commented Feb 17, 2026

Incrementally builds C99+ datetime support with addition of %t and %n with two lines of code. Also adds tests and updates documentation.

Continued effort from PR: #140647 , #144819.

Documentation drops (0) footnote.

Passed all tests.

Passed patchcheck.

Issue: #140715

Note, this PR originally only was for %t; %n was added 2026-02-25.


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

@StanFromIreland StanFromIreland self-assigned this Feb 17, 2026
Copy link
Member

@StanFromIreland StanFromIreland left a comment

Choose a reason for hiding this comment

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

This is quite an odd case, as per the standard for strftime, it is a \t character, however, for strptime():

A series of conversion specifications composed of %n, %t, white-space bytes, or any combination is executed by scanning up to the first non-white-space byte (which remains unscanned), or until no more characters can be scanned.

And, more straightforward:

Arbitrary whitespace.

Considering that this is the wide-spread behaviour, it should instead be r'\s+' for %n/%t (with additional tests), and add a note to the doc.

@jyalim
Copy link
Contributor Author

jyalim commented Feb 21, 2026

Thanks, this was a great catch that adds some power to %t for strptime. I've implemented the changes!

@jyalim
Copy link
Contributor Author

jyalim commented Feb 22, 2026

Thank you, the documentation changes were implemented.

Copy link
Member

@StanFromIreland StanFromIreland left a comment

Choose a reason for hiding this comment

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

We could also do \n now, since it is equivalent. (re-use the tests please)

jyalim and others added 2 commits February 25, 2026 22:25
typo fix

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
remove trailing whitespace

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
@jyalim jyalim changed the title gh-140715: Add %t format code support to strptime() gh-140715: Add %t and %n format codes support to strptime() Feb 26, 2026
@jyalim
Copy link
Contributor Author

jyalim commented Feb 26, 2026

Thanks! All the requested changes were implemented. The title and description of this PR were also updated to include %n.

@jyalim
Copy link
Contributor Author

jyalim commented Feb 28, 2026

Thank you, the tests have been merged and all requested changes have been implemented.

)

def test_strptime_n_and_t_format(self):
year, month, day = 2026, 2, 20
Copy link
Member

Choose a reason for hiding this comment

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

This is over-engineered, they don't change?

Copy link
Contributor Author

@jyalim jyalim Mar 1, 2026

Choose a reason for hiding this comment

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

Setting the year, month, and day names? They are reused twice in this test (ruling out test errors due to typos in literals) and arguably f"{year:04d}{ws}{month:02d}{ws}{day:02d}" is easier to comprehend than f"2026{ws}02{ws}02".

Could make them keyword arguments for the test methods instead?

jyalim and others added 4 commits March 1, 2026 07:49
clarify "arbitrary" with "zero or more"

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
clarify "arbitrary" with "zero or more"

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
…wmcM_.rst


Drop quotes around format directives

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
@StanFromIreland
Copy link
Member

Something broke with the CI, I'll try updating the branch.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants