Repository navigation
email.utils.parsedate() and email.utils.parsedate_tz() should return None when date cannot be parsed #60129
Description
Activity
Documentation (in Python 3.3) says that None is returned when date cannot be parsed.
In Python 3.2:
>> email.utils.parsedate("0")
>> email.utils.parsedate_tz("0")
>>In Python 3.3:
>>> email.utils.parsedate("0") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python3.3/email/utils.py", line 232, in parsedate return _parsedate(data) File "/usr/lib64/python3.3/email/_parseaddr.py", line 172, in parsedate t = parsedate_tz(data) File "/usr/lib64/python3.3/email/_parseaddr.py", line 51, in parsedate_tz if res[9] is None: TypeError: 'NoneType' object is not subscriptable >>> email.utils.parsedate_tz("0") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python3.3/email/utils.py", line 238, in parsedate_tz return _parsedate_tz(data) File "/usr/lib64/python3.3/email/_parseaddr.py", line 51, in parsedate_tz if res[9] is None: TypeError: 'NoneType' object is not subscriptable >>> email.utils.parsedate_to_datetime("0") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python3.3/email/utils.py", line 243, in parsedate_to_datetime *dtuple, tz = __parsedate_tz(data) TypeError: 'NoneType' object is not iterable >>>
Here is a patch.
Georg, this unfortunately represents a regression from 3.2 and should be fixed.
Hmm. Not sure why Georg didn't get auto-added.
Oh, and I'm purposely allowing parsedate_to_datetime throw exceptions. I suppose that should be documented, but that's a separate issue.
- changed the title
[-]email.utils.parsedate(), email.utils.parsedate_tz() and email.utils.parsedate_to_datetime() should return None when date cannot be parsed[/-][+]email.utils.parsedate() and email.utils.parsedate_tz() should return None when date cannot be parsed[/+]on Sep 16, 2012 I think that email.utils.parsedate_to_datetime("0") should raise ValueError instead of TypeError.
New changeset 3b03d31f6a79 by R David Murray in branch 'default':
bpo-15925: fix regression: return None for null and non-date strings.
http://hg.python.org/cpython/rev/3b03d31f6a79I don't think it is worth the extra code to convert the TypeError into a ValueError. We aren't very strict about the distinction between those two.
Leaving this open for Georg to transplant it to 3.3.0.
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Sep 22, 2012 This was committed to the release clone as c1e9a1fc6931.
New changeset c1e9a1fc6931 by Georg Brandl in branch 'default':
Closes bpo-15925: fix regression in parsedate() and parsedate_tz() that should return None if unable to parse the argument.
http://hg.python.org/cpython/rev/c1e9a1fc6931
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields: