New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
email.utils.parsedate() and email.utils.parsedate_tz() should return None when date cannot be parsed #60129
Comments
Documentation (in Python 3.3) says that None is returned when date cannot be parsed. In Python 3.2:
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. |
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': |
I 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. |
This was committed to the release clone as c1e9a1fc6931. |
New changeset c1e9a1fc6931 by Georg Brandl in branch 'default': |
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:
The text was updated successfully, but these errors were encountered: