classification
Title: email.utils.parsetime_tz does not return "None" as the tz offset
Type: behavior Stage: patch review
Components: Documentation Versions: Python 3.9, Python 3.8, Python 3.7, Python 3.6, Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: barry, docs@python, irishsmurf, maxking, r.david.murray, xtreak
Priority: normal Keywords: patch

Created on 2019-10-09 12:45 by irishsmurf, last changed 2019-10-09 13:36 by python-dev.

Pull Requests
URL Status Linked Edit
PR 16678 open python-dev, 2019-10-09 13:36
Messages (3)
msg354265 - (view) Author: David Kernan (irishsmurf) * Date: 2019-10-09 12:45
email.utils.parsetime_tz() is a function which attempts to parse a date, and returns a 10-item tuple.
The first 9 items represents a time, and the last item represents the timezone offset from UTC.

In Python 2, the original behavior was to return the date, and a "None" value when there was no timezone - this is documented here:
https://docs.python.org/3/library/email.utils.html#email.utils.parsedate_tz

In Python 3 however, the code specifically prevents "None" from being returned in place of a UTC offset:
https://github.com/python/cpython/blob/3.7/Lib/email/_parseaddr.py#L53-#L54

The Python 3 documentation for email.utils.parsetime_tz() - is still the same as the 2.7 documentation, and specifically mentions that should a timezone be missing from the string, the last item will be "None"

This isn't the case:

Python 3.6.8:
>>> import email.utils
>>> date_string = 'Wed, 09 Oct 2019 08:32:37'
>>> email.utils.parsedate_tz(date_string)
(2019, 10, 9, 8, 32, 37, 0, 1, -1, 0)
----

Python 2.7.16:
>>> import email.utils
>>> date_string = 'Wed, 09 Oct 2019 08:32:37'
>>> email.utils.parsedate_tz(date_string)
(2019, 10, 9, 8, 32, 37, 0, 1, -1, None)

---

Is this an error in code, or is it a mistake in the documentation?
msg354267 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python triager) Date: 2019-10-09 13:20
It looks like a documentation issue to me given the change and tests made in https://github.com/python/cpython/commit/875048bd4c95ae90c3e541cad681b11436ce1f3f
msg354268 - (view) Author: David Kernan (irishsmurf) * Date: 2019-10-09 13:25
Ah yes, thanks, this does seem pretty intentional.

I'll submit a PR for the documentation for this method for the affected version.
History
Date User Action Args
2019-10-09 13:36:40python-devsetkeywords: + patch
stage: patch review
pull_requests: + pull_request16261
2019-10-09 13:35:59irishsmurfsetassignee: docs@python

components: + Documentation, - email
nosy: + docs@python
2019-10-09 13:25:23irishsmurfsetmessages: + msg354268
2019-10-09 13:20:33xtreaksetnosy: + xtreak
messages: + msg354267
2019-10-09 13:14:52xtreaksetnosy: + maxking
2019-10-09 12:46:31irishsmurfsettitle: email.utils.parsetime_tz does not return "None" -> email.utils.parsetime_tz does not return "None" as the tz offset
2019-10-09 12:45:09irishsmurfsettype: behavior
2019-10-09 12:45:03irishsmurfcreate