From 9a4d2041f92ed59608e91e49f91e57027d0aaf3e Mon Sep 17 00:00:00 2001 From: Tiara Rodney Date: Sat, 6 Jun 2026 14:36:17 +0200 Subject: [PATCH] refactor: convert HttpResponse to frozen dataclass text becomes a derived property; reason is now optional. --- src/byteb4rb1e/utils/http/client.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/byteb4rb1e/utils/http/client.py b/src/byteb4rb1e/utils/http/client.py index 0962445..02b8cb6 100644 --- a/src/byteb4rb1e/utils/http/client.py +++ b/src/byteb4rb1e/utils/http/client.py @@ -5,6 +5,7 @@ Thin urllib wrapper with retry-on-rate-limit. No domain knowledge — GitHub, Bitbucket, etc. are handled by higher-level modules. """ +from dataclasses import dataclass import json import time from typing import Any, Dict, Optional @@ -13,17 +14,20 @@ import urllib.parse from warnings import warn +@dataclass(frozen=True) class HttpResponse: - def __init__(self, status: int, headers: dict, data: bytes, reason: str): - self.status_code = status - self.headers = headers - self.data = data - self.reason = reason - self.text = data.decode("utf-8", errors="replace") + status_code: int + headers: dict[str, str] + data: bytes + reason: Optional[str] = None def json(self): return json.loads(self.data.decode("utf-8")) + @property + def text(self) -> str: + return self.data.decode("utf-8", errors="replace") + def _request( url: str,