Author itchyny
Recipients itchyny
Date 2021-02-22.13:58:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
In Python 3.9.2, parsing 'z' (small letter) as '%z' (time zone offset) using datetime.strptime emits an IndexError.

>>> from datetime import datetime
>>> datetime.strptime('z', '%z')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/", line 568, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
  File "/usr/local/lib/python3.9/", line 453, in _strptime
    if z[3] == ':':
IndexError: string index out of range

I expect ValueError (or some another useful error) as follows.
ValueError: time data 'z' does not match format '%z'

This is caused by compiling '%z' to a pattern containing 'Z' (for UTC) with the IGNORECASE flag and accessing z[3] without noticing 'z' is accepted by the regexp.
Date User Action Args
2021-02-22 13:58:19itchynysetrecipients: + itchyny
2021-02-22 13:58:19itchynysetmessageid: <>
2021-02-22 13:58:19itchynylinkissue43295 messages
2021-02-22 13:58:19itchynycreate