Skip to content

Commit 5d7fcca

Browse files
Adopt shared plain-type helpers in transport base
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent d50c42e commit 5d7fcca

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

hyperbrowser/transport/base.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
)
88
from hyperbrowser.exceptions import HyperbrowserError
99
from hyperbrowser.mapping_utils import read_string_key_mapping
10+
from hyperbrowser.type_utils import is_plain_int, is_plain_string
1011

1112
T = TypeVar("T")
1213
_MAX_MODEL_NAME_DISPLAY_LENGTH = 120
@@ -20,7 +21,7 @@ def _safe_model_name(model: object) -> str:
2021
model_name = getattr(model, "__name__", "response model")
2122
except Exception:
2223
return "response model"
23-
if type(model_name) is not str:
24+
if not is_plain_string(model_name):
2425
return "response model"
2526
try:
2627
normalized_model_name = normalize_display_text(
@@ -41,12 +42,12 @@ def _format_mapping_key_for_error(key: str) -> str:
4142

4243

4344
def _normalize_transport_api_key(api_key: str) -> str:
44-
if type(api_key) is not str:
45+
if not is_plain_string(api_key):
4546
raise HyperbrowserError("api_key must be a string")
4647

4748
try:
4849
normalized_api_key = api_key.strip()
49-
if type(normalized_api_key) is not str:
50+
if not is_plain_string(normalized_api_key):
5051
raise TypeError("normalized api_key must be a string")
5152
except HyperbrowserError:
5253
raise
@@ -93,7 +94,7 @@ class APIResponse(Generic[T]):
9394
"""
9495

9596
def __init__(self, data: Optional[Union[dict, T]] = None, status_code: int = 200):
96-
if type(status_code) is not int:
97+
if not is_plain_int(status_code):
9798
raise HyperbrowserError("status_code must be an integer")
9899
if not (_MIN_HTTP_STATUS_CODE <= status_code <= _MAX_HTTP_STATUS_CODE):
99100
raise HyperbrowserError("status_code must be between 100 and 599")

0 commit comments

Comments
 (0)