Skip to content

Commit 43b7aa7

Browse files
committed
Restore deprecated status code aliases
1 parent 6f38ddf commit 43b7aa7

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

src/httpx2/httpx2/_status_codes.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@
1616

1717

1818
class _CodesMeta(EnumMeta):
19-
def __getattr__(cls, name: str) -> codes:
19+
def __getattribute__(cls, name: str) -> object:
2020
if name in _DEPRECATED_CODES:
2121
new_name = _DEPRECATED_CODES[name]
2222
warnings.warn(
2323
f"'{name}' is deprecated. Use '{new_name}' instead.",
2424
category=DeprecationWarning,
2525
stacklevel=2,
2626
)
27-
return cls[new_name]
28-
raise AttributeError(name)
27+
return super().__getattribute__(name)
2928

3029

3130
class codes(IntEnum, metaclass=_CodesMeta):
@@ -178,7 +177,13 @@ def is_error(cls, value: int) -> bool:
178177
NOT_EXTENDED = 510, "Not Extended"
179178
NETWORK_AUTHENTICATION_REQUIRED = 511, "Network Authentication Required"
180179

180+
# Deprecated aliases for names replaced by RFC 9110.
181+
REQUEST_ENTITY_TOO_LARGE = CONTENT_TOO_LARGE
182+
REQUEST_URI_TOO_LONG = URI_TOO_LONG
183+
REQUESTED_RANGE_NOT_SATISFIABLE = RANGE_NOT_SATISFIABLE
184+
UNPROCESSABLE_ENTITY = UNPROCESSABLE_CONTENT
185+
181186

182187
# Include lower-case styles for `requests` compatibility.
183-
for code in codes:
184-
setattr(codes, code._name_.lower(), int(code))
188+
for name, code in codes.__members__.items():
189+
setattr(codes, name.lower(), int(code))

tests/httpx2/test_status_codes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ def test_pre_rfc9110_aliases_are_deprecated(old_name: str, new_name: str) -> Non
5151
with pytest.warns(DeprecationWarning, match=msg):
5252
assert getattr(httpx2.codes, old_name) == httpx2.codes[new_name]
5353

54+
assert old_name in httpx2.codes.__members__
55+
assert httpx2.codes[old_name] == httpx2.codes[new_name]
56+
assert getattr(httpx2.codes, old_name.lower()) == httpx2.codes[new_name]
57+
5458

5559
def test_unknown_status_code_attribute_raises() -> None:
5660
name = "NOT_A_REAL_CODE"

0 commit comments

Comments
 (0)