summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/_strptime.py2
-rw-r--r--Lib/test/datetimetester.py1
-rw-r--r--Misc/NEWS.d/next/Library/2021-02-22-22-54-40.bpo-43295.h_ffu7.rst2
3 files changed, 4 insertions, 1 deletions
diff --git a/Lib/_strptime.py b/Lib/_strptime.py
index 5df37f5..b97dfcc 100644
--- a/Lib/_strptime.py
+++ b/Lib/_strptime.py
@@ -201,7 +201,7 @@ class TimeRE(dict):
#XXX: Does 'Y' need to worry about having less or more than
# 4 digits?
'Y': r"(?P<Y>\d\d\d\d)",
- 'z': r"(?P<z>[+-]\d\d:?[0-5]\d(:?[0-5]\d(\.\d{1,6})?)?|Z)",
+ 'z': r"(?P<z>[+-]\d\d:?[0-5]\d(:?[0-5]\d(\.\d{1,6})?)?|(?-i:Z))",
'A': self.__seqToRE(self.locale_time.f_weekday, 'A'),
'a': self.__seqToRE(self.locale_time.a_weekday, 'a'),
'B': self.__seqToRE(self.locale_time.f_month[1:], 'B'),
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index 775d315..316cf0b 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -2609,6 +2609,7 @@ class TestDateTime(TestDate):
with self.assertRaises(ValueError): strptime("-2400", "%z")
with self.assertRaises(ValueError): strptime("-000", "%z")
+ with self.assertRaises(ValueError): strptime("z", "%z")
def test_strptime_single_digit(self):
# bpo-34903: Check that single digit dates and times are allowed.
diff --git a/Misc/NEWS.d/next/Library/2021-02-22-22-54-40.bpo-43295.h_ffu7.rst b/Misc/NEWS.d/next/Library/2021-02-22-22-54-40.bpo-43295.h_ffu7.rst
new file mode 100644
index 0000000..ac9a5c9
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-02-22-22-54-40.bpo-43295.h_ffu7.rst
@@ -0,0 +1,2 @@
+:meth:`datetime.datetime.strptime` now raises ``ValueError`` instead of
+``IndexError`` when matching ``'z'`` with the ``%z`` format specifier.