James Bennett on Nostr: A quick #Python tip/plea: the standard library "http" module, since Python 3.5, has ...
A quick #Python tip/plea: the standard library "http" module, since Python 3.5, has contained an enum of the HTTP status codes: https://docs.python.org/3/library/http.html#http.HTTPStatus
You can import it and write things like
assert my_success_response.status_code == HTTPStatus.OK
And this replaces both raw integer "magic number" values and framework-specific constants/enums, so you no longer have to remember that Web Framework A calls it "HTTP_200_OK" while Framework B calls it "HTTP_STATUS_OK", etc.
I plan to ensure all of my own projects switch to this as their standard way of referencing status codes, and urge everyone else to do the same (and web frameworks to deprecate and begin removal of their own variations on status-code constants/enums).
You can import it and write things like
assert my_success_response.status_code == HTTPStatus.OK
And this replaces both raw integer "magic number" values and framework-specific constants/enums, so you no longer have to remember that Web Framework A calls it "HTTP_200_OK" while Framework B calls it "HTTP_STATUS_OK", etc.
I plan to ensure all of my own projects switch to this as their standard way of referencing status codes, and urge everyone else to do the same (and web frameworks to deprecate and begin removal of their own variations on status-code constants/enums).