Skip to content

Commit d52d5f3

Browse files
Adopt shared plain-string helper in client base
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 68fa983 commit d52d5f3

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

hyperbrowser/client/base.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from hyperbrowser.exceptions import HyperbrowserError
66
from ..config import ClientConfig
77
from ..transport.base import AsyncTransportStrategy, SyncTransportStrategy
8+
from ..type_utils import is_plain_string
89

910

1011
class HyperbrowserBase:
@@ -36,11 +37,11 @@ def __init__(
3637
raise HyperbrowserError(
3738
"API key must be provided via `api_key` or HYPERBROWSER_API_KEY"
3839
)
39-
if type(resolved_api_key) is not str:
40+
if not is_plain_string(resolved_api_key):
4041
raise HyperbrowserError("api_key must be a string")
4142
try:
4243
normalized_resolved_api_key = resolved_api_key.strip()
43-
if type(normalized_resolved_api_key) is not str:
44+
if not is_plain_string(normalized_resolved_api_key):
4445
raise TypeError("normalized api_key must be a string")
4546
except HyperbrowserError:
4647
raise
@@ -128,11 +129,11 @@ def _parse_url_components(
128129
original_error=exc,
129130
) from exc
130131
if (
131-
type(parsed_url_scheme) is not str
132-
or type(parsed_url_netloc) is not str
133-
or type(parsed_url_path) is not str
134-
or type(parsed_url_query) is not str
135-
or type(parsed_url_fragment) is not str
132+
not is_plain_string(parsed_url_scheme)
133+
or not is_plain_string(parsed_url_netloc)
134+
or not is_plain_string(parsed_url_path)
135+
or not is_plain_string(parsed_url_query)
136+
or not is_plain_string(parsed_url_fragment)
136137
):
137138
raise HyperbrowserError(
138139
f"{component_label} parser returned invalid URL components"
@@ -146,11 +147,11 @@ def _parse_url_components(
146147
)
147148

148149
def _build_url(self, path: str) -> str:
149-
if type(path) is not str:
150+
if not is_plain_string(path):
150151
raise HyperbrowserError("path must be a string")
151152
try:
152153
stripped_path = path.strip()
153-
if type(stripped_path) is not str:
154+
if not is_plain_string(stripped_path):
154155
raise TypeError("normalized path must be a string")
155156
has_surrounding_whitespace = stripped_path != path
156157
is_empty_path = len(stripped_path) == 0

0 commit comments

Comments
 (0)