mirror of
https://github.com/python/cpython.git
synced 2025-10-17 04:08:28 +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
|
@ -2793,6 +2793,19 @@ class TestDateTime(TestDate):
|
|||
newdate = strptime(string, format)
|
||||
self.assertEqual(newdate, target, msg=reason)
|
||||
|
||||
def test_strptime_leap_year(self):
|
||||
# GH-70647: warns if parsing a format with a day and no year.
|
||||
with self.assertRaises(ValueError):
|
||||
# The existing behavior that GH-70647 seeks to change.
|
||||
self.theclass.strptime('02-29', '%m-%d')
|
||||
with self.assertWarnsRegex(DeprecationWarning,
|
||||
r'.*day of month without a year.*'):
|
||||
self.theclass.strptime('03-14.159265', '%m-%d.%f')
|
||||
with self._assertNotWarns(DeprecationWarning):
|
||||
self.theclass.strptime('20-03-14.159265', '%y-%m-%d.%f')
|
||||
with self._assertNotWarns(DeprecationWarning):
|
||||
self.theclass.strptime('02-29,2024', '%m-%d,%Y')
|
||||
|
||||
def test_more_timetuple(self):
|
||||
# This tests fields beyond those tested by the TestDate.test_timetuple.
|
||||
t = self.theclass(2004, 12, 31, 6, 22, 33)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue