Add RFC 9110 status code constants - #1069
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
1 issue found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/httpx2/httpx2/_status_codes.py">
<violation number="1" location="src/httpx2/httpx2/_status_codes.py:160">
P3: The alias definitions preserve the original UPPERCASE constant names, but `codes.request_entity_too_large` etc. (the lowercase `requests`-compatible forms) are silently dropped because the `for code in codes:` loop only iterates over canonical members, not aliases. Anyone migrating from `httpx.codes.request_entity_too_large` will get an `AttributeError`. Consider preserving these too, either via explicit `setattr` calls after the loop or by adding them as additional alias entries.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| NETWORK_AUTHENTICATION_REQUIRED = 511, "Network Authentication Required" | ||
|
|
||
| # for backwards compatibility, keep the old constants around | ||
| REQUEST_ENTITY_TOO_LARGE = CONTENT_TOO_LARGE |
There was a problem hiding this comment.
P3: The alias definitions preserve the original UPPERCASE constant names, but codes.request_entity_too_large etc. (the lowercase requests-compatible forms) are silently dropped because the for code in codes: loop only iterates over canonical members, not aliases. Anyone migrating from httpx.codes.request_entity_too_large will get an AttributeError. Consider preserving these too, either via explicit setattr calls after the loop or by adding them as additional alias entries.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/httpx2/httpx2/_status_codes.py, line 160:
<comment>The alias definitions preserve the original UPPERCASE constant names, but `codes.request_entity_too_large` etc. (the lowercase `requests`-compatible forms) are silently dropped because the `for code in codes:` loop only iterates over canonical members, not aliases. Anyone migrating from `httpx.codes.request_entity_too_large` will get an `AttributeError`. Consider preserving these too, either via explicit `setattr` calls after the loop or by adding them as additional alias entries.</comment>
<file context>
@@ -156,6 +156,12 @@ def is_error(cls, value: int) -> bool:
NETWORK_AUTHENTICATION_REQUIRED = 511, "Network Authentication Required"
+ # for backwards compatibility, keep the old constants around
+ REQUEST_ENTITY_TOO_LARGE = CONTENT_TOO_LARGE
+ REQUEST_URI_TOO_LONG = URI_TOO_LONG
+ REQUESTED_RANGE_NOT_SATISFIABLE = RANGE_NOT_SATISFIABLE
</file context>
197af58 to
b1cc86e
Compare
| # for backwards compatibility, keep the old constants around | ||
| REQUEST_ENTITY_TOO_LARGE = CONTENT_TOO_LARGE | ||
| REQUEST_URI_TOO_LONG = URI_TOO_LONG | ||
| REQUESTED_RANGE_NOT_SATISFIABLE = RANGE_NOT_SATISFIABLE | ||
| UNPROCESSABLE_ENTITY = UNPROCESSABLE_CONTENT |
There was a problem hiding this comment.
We need to use __getattr__ and deprecate the old ones.
| * RFC 9110: HTTP Semantics | ||
| obsoletes 7231, which obsoletes 2616. Obsoletes 7238 |
There was a problem hiding this comment.
| * RFC 9110: HTTP Semantics | |
| obsoletes 7231, which obsoletes 2616. Obsoletes 7238 | |
| * RFC 9110: HTTP Semantics, obsoletes 7231 & 7238 |
|
|
||
|
|
||
| def test_rfc9110_status_texts() -> None: | ||
| assert httpx2.codes.get_reason_phrase(413) == "Content Too Large" | ||
| assert httpx2.codes.get_reason_phrase(414) == "URI Too Long" | ||
| assert httpx2.codes.get_reason_phrase(416) == "Range Not Satisfiable" | ||
| assert httpx2.codes.get_reason_phrase(422) == "Unprocessable Content" | ||
|
|
||
|
|
||
| def test_pre_rfc9110_aliases_still_work() -> None: | ||
| # kept for backwards compatibility with the pre-RFC 9110 constant names | ||
| assert httpx2.codes.REQUEST_ENTITY_TOO_LARGE == httpx2.codes.CONTENT_TOO_LARGE # type: ignore[comparison-overlap] | ||
| assert httpx2.codes.REQUEST_URI_TOO_LONG == httpx2.codes.URI_TOO_LONG | ||
| assert httpx2.codes.REQUESTED_RANGE_NOT_SATISFIABLE == httpx2.codes.RANGE_NOT_SATISFIABLE | ||
| assert httpx2.codes.UNPROCESSABLE_ENTITY == httpx2.codes.UNPROCESSABLE_CONTENT |
68e7f79 to
8d830b2
Compare
RFC 9110 (HTTP Semantics) renamed several status phrases and obsoletes RFC 7231/7238. Add the new constant names and phrases, deprecating the old constant names as aliases for backwards compatibility: - REQUEST_ENTITY_TOO_LARGE -> CONTENT_TOO_LARGE (413) - REQUEST_URI_TOO_LONG -> URI_TOO_LONG (414) - REQUESTED_RANGE_NOT_SATISFIABLE -> RANGE_NOT_SATISFIABLE (416) - UNPROCESSABLE_ENTITY -> UNPROCESSABLE_CONTENT (422)
8d830b2 to
16c1de0
Compare
| stacklevel=2, | ||
| ) | ||
| return cls[new_name] | ||
| raise AttributeError(name) |
There was a problem hiding this comment.
Does this exception matches the message you'd receive before adding this metadata?
RFC 9110 (HTTP Semantics) obsoletes RFC 7231 (which obsoletes 2616) and RFC 7238, and renamed several status phrases. This adds the new constant names and phrases, keeping the old constant names as aliases for backwards compatibility:
REQUEST_ENTITY_TOO_LARGE→CONTENT_TOO_LARGE(413)REQUEST_URI_TOO_LONG→URI_TOO_LONG(414)REQUESTED_RANGE_NOT_SATISFIABLE→RANGE_NOT_SATISFIABLE(416)UNPROCESSABLE_ENTITY→UNPROCESSABLE_CONTENT(422)Ported from a fix I originally carried in the httpxyz fork.