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 20 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 |
| self.theclass(test_year,test_month,test_day) | ||
| ) | ||
|
|
||
| def test_strptime_n_format(self): |
There was a problem hiding this comment.
The two tests can be merged with e.g. for d in ('n', 't'): ...
| ) | ||
|
|
||
| def test_strptime_t_format(self): | ||
| test_year,test_month,test_day = 2026,2,20 |
There was a problem hiding this comment.
| test_year,test_month,test_day = 2026,2,20 | |
| year, month, day = 2026, 2, 20 |
Shorter names are clearer, and please follow PEP 8's whitespace guide.
| time.strptime(test_date, "%m/%d/%y") | ||
| ) | ||
|
|
||
| def test_strptime_t_format(self): |
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/