Skip to content

Fix inconsistent HTTPStatus string representation#60

Merged
abersheeran merged 1 commit intoabersheeran:masterfrom
nyanloutre:patch-1
Jul 26, 2024
Merged

Fix inconsistent HTTPStatus string representation#60
abersheeran merged 1 commit intoabersheeran:masterfrom
nyanloutre:patch-1

Conversation

@nyanloutre
Copy link
Copy Markdown
Contributor

Hello,

In some python environments, HTTPStatus conversion to string will not result in their value but in their repr ("<HTTPStatus.OK: 200>" instead of "200")

It leads to the following error in mod_wsgi:

ValueError: status code is not a 3 digit integer

because the returned status is "<HTTPStatus.OK: 200> OK" instead of "200 OK"

Explicit call to the value property ensure that the fstring contains the numerical representation of the HTTP code and not the human readable representation of the enum.

mod_wsgi behavior:

>>> str(HTTPStatus.OK)
'<HTTPStatus.OK: 200>'
>>> HTTPStatus.OK.__str__
<method-wrapper '__str__' of HTTPStatus object at 0x7fb3d52bbd50>

python CLI behavior

>>> str(HTTPStatus.OK)
'200'
>>> HTTPStatus.OK.__str__
<method-wrapper '__repr__' of HTTPStatus object at 0x7faa19c06350>

In some python environments, HTTPStatus conversion to string will not result in their value but in their repr ("<HTTPStatus.OK: 200>" instead of "200")
@abersheeran abersheeran merged commit 91188bf into abersheeran:master Jul 26, 2024
@abersheeran
Copy link
Copy Markdown
Owner

Well done, once again improving our compatibility.

@nyanloutre nyanloutre deleted the patch-1 branch July 26, 2024 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants