Author erik.bray
Recipients belopolsky, eric.smith, erik.bray, matrixise, miss-islington, mjsaah, p-ganssle, pablogsal, terry.reedy, thatiparthy, vstinner, xdegaye, xtreak
Date 2019-06-12.14:35:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1560350113.85.0.703026867764.issue35066@roundup.psfhosted.org>
In-reply-to
Content
FWIW (unsurprisingly) the new test added here is broken on Cygwin, whose libc's (newlib) behavior in this undefined case.  So I get:

>>> from datetime import date
>>> t = date(2005, 1, 1)
>>> t.strftime("%Y")  # ok
'2005'
>>> t.strftime("%%")  # ok
'%'
>>> t.strftime("%")  # undefined behavior
''
>>> t.strftime("%Y %")  # undefined behavior; discards the whole format string
''
>>> t.strftime("%Y%Q")  # undefined format; discards the whole format string
''

This behavior is user-hostile I think; it should raise a ValueError instead of just return an empty string.  I would have suggested the same for the trailing '%' case, though I understand the goal of this issue was consistency.

Also worth noting that both before and after this patch:

>>> import time
>>> time.strftime('%')
''

So the question of consistency between the interfaces, which was the main point of this issue, was already resolved in this case, and the *inconsistency* observed was dependent on system-dependent behavior.

For now I might propose doing away with this test in its current form, and just test

assert t.strftime('%') == time.strftime('%')

or something like that.

I agree with Victor that trying to make the strftime experience consistent across system-dependent quirks is a worthy goal, but that goes deeper than just this trailing '%' case.
History
Date User Action Args
2019-06-12 14:35:13erik.braysetrecipients: + erik.bray, terry.reedy, belopolsky, vstinner, eric.smith, xdegaye, matrixise, thatiparthy, p-ganssle, pablogsal, miss-islington, xtreak, mjsaah
2019-06-12 14:35:13erik.braysetmessageid: <1560350113.85.0.703026867764.issue35066@roundup.psfhosted.org>
2019-06-12 14:35:13erik.braylinkissue35066 messages
2019-06-12 14:35:13erik.braycreate