classification
Title: http.client status code constants incompatible with Python 3.4
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: ethan.furman, martin.panter, serhiy.storchaka, srittau
Priority: normal Keywords: 3.5regression

Created on 2016-01-15 13:10 by srittau, last changed 2017-10-23 09:00 by serhiy.storchaka. This issue is now closed.

Messages (8)
msg258291 - (view) Author: Sebastian Rittau (srittau) * Date: 2016-01-15 13:10
The HTTP status code constants in Python 3.5 http.client are not compatible with the constants in Python 3.4, since the str() behaviour is different. This breaks code: 

srittau@moby:~$ python3.5
Python 3.5.1+ (default, Jan 13 2016, 15:09:18) 
[GCC 5.3.1 20160101] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import http.client
>>> str(http.client.OK)
'HTTPStatus.OK'

vs:

rittau@moby:~$ python3.4
Python 3.4.4 (default, Jan  5 2016, 15:35:18) 
[GCC 5.3.1 20160101] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import http.client
>>> str(http.client.OK)
'200'
msg258302 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2016-01-15 16:15
These changes were made in issue21793.
msg258306 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-01-15 16:28
Yes, this a side effect of using more human-friendly enums. This is not a problem if string representation is used in formatting human-readable messages, but if you need numerical representation, you could use str(int(code)), '%d' % code or '{:d}'.format(code).
msg258309 - (view) Author: Sebastian Rittau (srittau) * Date: 2016-01-15 16:59
It is no doubt that is easy to work around. Once I found the problem it took about five minutes to fix it and roll a new release. And of course for Python 3.5+ code it is better to use the enum http.HTTPStatus directly (I actually like that enum a lot). But this breaks existing code that should not break. It might be too late to change now, though.

As a side note, I would also have preferred str(HTTPStatus.OK) to return "OK" or "200" - the latter would mirror default format behaviour - instead of "HTTPStatus.OK", but this may be too late as well.
msg258334 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-01-15 22:24
This affected the HTTP server log messages, discussed from <https://bugs.python.org/issue21793#msg235547> onwards. The first three patches proposed changed the HTTPStatus.__str__() implementation, which would have avoided the problem in general. But Demian’s final patch made a special case of checking for HTTPStatus objects in the logging code instead.

IMO it may have been better to change HTTPStatus.__str__() to use int.__str__() at the time.
msg258335 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2016-01-15 22:37
Not using Enum's __str__ was discussed (I think during the initial Enum threads when PEP435 was being debated) and IIRC Guido was strongly against it as it took away half the purpose of using an Enum.
msg304781 - (view) Author: Sebastian Rittau (srittau) * Date: 2017-10-23 08:17
I take the liberty of closing this "wont fix". Changing the behaviour would most likely do more harm than good. If one of the maintainers disagrees, please reopen. :)
msg304784 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-10-23 09:00
Thank you Sebastian.
History
Date User Action Args
2017-10-23 09:00:17serhiy.storchakasetmessages: + msg304784
2017-10-23 08:17:31srittausetstatus: open -> closed
resolution: wont fix
messages: + msg304781

stage: resolved
2016-01-15 22:37:11ethan.furmansetmessages: + msg258335
2016-01-15 22:24:06martin.pantersetnosy: + martin.panter
messages: + msg258334
2016-01-15 16:59:20srittausetmessages: + msg258309
2016-01-15 16:28:22serhiy.storchakasetmessages: + msg258306
2016-01-15 16:15:32ethan.furmansetmessages: + msg258302
2016-01-15 16:09:59ethan.furmansetnosy: + ethan.furman
2016-01-15 14:34:54SilentGhostsetkeywords: + 3.5regression
nosy: + serhiy.storchaka

type: behavior
versions: + Python 3.6
2016-01-15 13:10:03srittaucreate