mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
GH-70647: Deprecate strptime day of month parsing without a year present to avoid leap-year bugs (GH-117107)
This commit is contained in:
parent
595bb496b0
commit
33ee5cb3e9
7 changed files with 117 additions and 1 deletions
|
@ -277,6 +277,8 @@ class TimeTestCase(unittest.TestCase):
|
|||
'j', 'm', 'M', 'p', 'S',
|
||||
'U', 'w', 'W', 'x', 'X', 'y', 'Y', 'Z', '%'):
|
||||
format = '%' + directive
|
||||
if directive == 'd':
|
||||
format += ',%Y' # Avoid GH-70647.
|
||||
strf_output = time.strftime(format, tt)
|
||||
try:
|
||||
time.strptime(strf_output, format)
|
||||
|
@ -299,6 +301,12 @@ class TimeTestCase(unittest.TestCase):
|
|||
time.strptime('19', '%Y %')
|
||||
self.assertIs(e.exception.__suppress_context__, True)
|
||||
|
||||
def test_strptime_leap_year(self):
|
||||
# GH-70647: warns if parsing a format with a day and no year.
|
||||
with self.assertWarnsRegex(DeprecationWarning,
|
||||
r'.*day of month without a year.*'):
|
||||
time.strptime('02-07 18:28', '%m-%d %H:%M')
|
||||
|
||||
def test_asctime(self):
|
||||
time.asctime(time.gmtime(self.t))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue