gh-140715: Add %t and %n format codes support to strptime()#144896
gh-140715: Add %t and %n format codes support to strptime()#144896jyalim wants to merge 26 commits intopython:mainfrom
Conversation
StanFromIreland
left a comment
There was a problem hiding this comment.
This is quite an odd case, as per the standard for strftime, it is a \t character, however, for strptime():
And, more straightforward:
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.
|
Thanks, this was a great catch that adds some power to |
|
Thank you, the documentation changes were implemented. |
StanFromIreland
left a comment
There was a problem hiding this comment.
We could also do \n now, since it is equivalent. (re-use the tests please)
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>
|
Thanks! All the requested changes were implemented. The title and description of this PR were also updated to include |
|
Thank you, the tests have been merged and all requested changes have been implemented. |
Misc/NEWS.d/next/Library/2026-02-17-03-43-07.gh-issue-140715.twmcM_.rst
Outdated
Show resolved
Hide resolved
| ) | ||
|
|
||
| def test_strptime_n_and_t_format(self): | ||
| year, month, day = 2026, 2, 20 |
There was a problem hiding this comment.
This is over-engineered, they don't change?
There was a problem hiding this comment.
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?
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>
|
Something broke with the CI, I'll try updating the branch. |
Incrementally builds C99+ datetime support with addition of
%tand%nwith 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
str*timeto C11 format codes #140715Note, this PR originally only was for
%t;%nwas added 2026-02-25.📚 Documentation preview 📚: https://cpython-previews--144896.org.readthedocs.build/