Skip to content
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

Fix inconsistent HTTPStatus string representation #60

Merged
merged 1 commit into from
Jul 26, 2024
Merged

Fix inconsistent HTTPStatus string representation #60

merged 1 commit into from
Jul 26, 2024

Conversation

nyanloutre
Copy link
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
16 checks passed
@abersheeran
Copy link
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