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 33 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
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. |
|
Thanks! Changes have been made. |
Lib/test/datetimetester.py
Outdated
|
|
||
| def test_strptime_n_and_t_format(self): | ||
| whitespaces = ('', ' ', '\t', '\r', '\v', '\n', '\f') | ||
| for fd in ('n', 't'): |
There was a problem hiding this comment.
Would it make sense to also test '%n%t' and the non-empty whitespaces as part of the pattern?
There was a problem hiding this comment.
Would it make sense to add whitespace to the table in the docs? (It already worked before, but AFAIK wasn't documented/tested.)
There was a problem hiding this comment.
Commit d6ca685 added '%n%t' and '%t%n'.
The final test for each whitespace format directive is ' \t\r\v\n\f', due to the ''.join(whitespaces) argument in the loop. Did you have another non-empty whitespace pattern in mind?
I'm all for improved documentation, could you clarify what you are envisioning? The whitespace format directives (%n and %t) are specified in the format directive table.
PEP 8 fix on existing code Co-authored-by: Petr Viktorin <encukou@gmail.com>
PEP 8 comma for exploded function arguments Co-authored-by: Petr Viktorin <encukou@gmail.com>
…lso add PEP 8 trailing commas to all exploded function arguments
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/