Skip to content

Commit 662076e

Browse files
Use plain-string helper consistently in error utils
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent db41b33 commit 662076e

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

hyperbrowser/transport/error_utils.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ def _safe_to_string(value: Any) -> str:
5454
normalized_value = str(value)
5555
except Exception:
5656
return f"<unstringifiable {type(value).__name__}>"
57-
if type(normalized_value) is not str:
57+
if not _is_plain_string(normalized_value):
5858
return f"<{type(value).__name__}>"
5959
try:
6060
sanitized_value = "".join(
6161
"?" if ord(character) < 32 or ord(character) == 127 else character
6262
for character in normalized_value
6363
)
64-
if type(sanitized_value) is not str:
64+
if not _is_plain_string(sanitized_value):
6565
return f"<{type(value).__name__}>"
6666
if sanitized_value.strip():
6767
return sanitized_value
@@ -85,7 +85,7 @@ def _has_non_blank_text(value: Any) -> bool:
8585
return False
8686
try:
8787
stripped_value = value.strip()
88-
if type(stripped_value) is not str:
88+
if not _is_plain_string(stripped_value):
8989
return False
9090
return bool(stripped_value)
9191
except Exception:
@@ -111,16 +111,16 @@ def _normalize_request_method(method: Any) -> str:
111111
except Exception:
112112
return "UNKNOWN"
113113
try:
114-
if type(raw_method) is not str:
114+
if not _is_plain_string(raw_method):
115115
return "UNKNOWN"
116116
stripped_method = raw_method.strip()
117-
if type(stripped_method) is not str or not stripped_method:
117+
if not _is_plain_string(stripped_method) or not stripped_method:
118118
return "UNKNOWN"
119119
normalized_method = stripped_method.upper()
120-
if type(normalized_method) is not str:
120+
if not _is_plain_string(normalized_method):
121121
return "UNKNOWN"
122122
lowered_method = normalized_method.lower()
123-
if type(lowered_method) is not str:
123+
if not _is_plain_string(lowered_method):
124124
return "UNKNOWN"
125125
except Exception:
126126
return "UNKNOWN"
@@ -159,13 +159,13 @@ def _normalize_request_url(url: Any) -> str:
159159
return "unknown URL"
160160

161161
try:
162-
if type(raw_url) is not str:
162+
if not _is_plain_string(raw_url):
163163
return "unknown URL"
164164
normalized_url = raw_url.strip()
165-
if type(normalized_url) is not str or not normalized_url:
165+
if not _is_plain_string(normalized_url) or not normalized_url:
166166
return "unknown URL"
167167
lowered_url = normalized_url.lower()
168-
if type(lowered_url) is not str:
168+
if not _is_plain_string(lowered_url):
169169
return "unknown URL"
170170
except Exception:
171171
return "unknown URL"
@@ -201,7 +201,7 @@ def _normalize_response_text_for_error_message(response_text: Any) -> str:
201201
if _is_plain_string(response_text):
202202
try:
203203
normalized_response_text = "".join(character for character in response_text)
204-
if type(normalized_response_text) is not str:
204+
if not _is_plain_string(normalized_response_text):
205205
raise TypeError("normalized response text must be a string")
206206
return normalized_response_text
207207
except Exception:
@@ -222,7 +222,7 @@ def _stringify_error_value(value: Any, *, _depth: int = 0) -> str:
222222
if _is_plain_string(value):
223223
try:
224224
normalized_value = "".join(character for character in value)
225-
if type(normalized_value) is not str:
225+
if not _is_plain_string(normalized_value):
226226
raise TypeError("normalized error value must be a string")
227227
return normalized_value
228228
except Exception:
@@ -299,7 +299,7 @@ def _fallback_message() -> str:
299299
break
300300
else:
301301
extracted_message = _stringify_error_value(error_data)
302-
elif type(error_data) is str:
302+
elif _is_plain_string(error_data):
303303
extracted_message = error_data
304304
else:
305305
extracted_message = _stringify_error_value(error_data)

0 commit comments

Comments
 (0)