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

Single consistent name for status codes #1088

Merged
merged 3 commits into from
Jul 27, 2020

Conversation

tomchristie
Copy link
Member

For consideration.

Currently we're exposing both httpx.StatusCodes and httpx.codes for working with status codes.

We're only documenting httpx.codes, and we probably only want a single canonical name here, right?

The documentation could also do with being expanded, at the very least in the API section.

Usages are like...

>>> httpx.codes.OK
<codes.OK: 200>
>>> httpx.codes.OK == 200
True
>>> httpx.codes.get_reason_phrase(200)
'OK'
>>> httpx.codes.is_error(400)
True
>>> httpx.codes.is_redirect(400)
False
>>> httpx.codes.is_client_error(400)
True
>>> httpx.codes.is_server_error(400)
False
>>> httpx.codes(200).phrase
'OK'
>>> httpx.codes(200).value
200

Copy link
Member

@jcugat jcugat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, makes sense 👍

@jcugat
Copy link
Member

jcugat commented Jul 25, 2020

There are some usages in the wild of StatusCode, but I guess we are fine breaking compatibility with this before 1.0 right?

Copy link
Member

@florimondmanca florimondmanca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, httpx.codes is the documented one for now, but...

I personally feel like httpx.StatusCode would be a less surprising and a more natural option...

I initially thought httpx.codes meant that we refactored things to have a codes.py module, with plain functions as well as a .__call__() function - but then realized that the latter is probably not valid Python?

Anyway, I mean that httpx.codes looks like a module access, while it actually refers to a standard enum. In my experience enums are generally named after the singular of what they refer to, hence httpx.StatusCode?

So that would give us:

httpx.StatusCode.OK
httpx.StatusCode(200)
httpx.StatusCode.is_client_error(400)

@florimondmanca
Copy link
Member

florimondmanca commented Jul 25, 2020

I'm not absolute on either option though and pretty much bikeshedding at this point...

The important bit is that we should have a single status codes enum, that I agree. :)

Minimizing breaking changes on httpx.codes (even with a smooth deprecation path) is a strong contender as well.

@tomchristie
Copy link
Member Author

I've updated this with a more gentle deprecation of httpx.StatusCode.

@tomchristie tomchristie added this to the v0.14 milestone Jul 27, 2020
@tomchristie tomchristie mentioned this pull request Jul 27, 2020
11 tasks
@tomchristie tomchristie added the user-experience Ensuring that users have a good experience using the library label Jul 27, 2020
@tomchristie tomchristie merged commit 35f09d1 into master Jul 27, 2020
@tomchristie tomchristie deleted the single-consistent-name-for-statuscodes branch July 27, 2020 13:35
@tomchristie tomchristie mentioned this pull request Aug 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user-experience Ensuring that users have a good experience using the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants