Skip to content

Commit dfd786f

Browse files
Require concrete base URL input types
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 9b21b53 commit dfd786f

File tree

2 files changed

+4
-34
lines changed

2 files changed

+4
-34
lines changed

hyperbrowser/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def _safe_unquote(value: str, *, component_label: str) -> str:
112112

113113
@staticmethod
114114
def normalize_base_url(base_url: str) -> str:
115-
if not isinstance(base_url, str):
115+
if type(base_url) is not str:
116116
raise HyperbrowserError("base_url must be a string")
117117
try:
118118
stripped_base_url = base_url.strip()

tests/test_config.py

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -295,43 +295,13 @@ def test_client_config_rejects_non_string_values():
295295
ClientConfig(api_key="bad\nkey")
296296

297297

298-
def test_client_config_normalize_base_url_wraps_strip_runtime_errors():
298+
def test_client_config_normalize_base_url_rejects_string_subclass_inputs():
299299
class _BrokenBaseUrl(str):
300-
def strip(self, chars=None): # type: ignore[override]
301-
_ = chars
302-
raise RuntimeError("base_url strip exploded")
303-
304-
with pytest.raises(HyperbrowserError, match="Failed to normalize base_url") as exc_info:
305-
ClientConfig.normalize_base_url(_BrokenBaseUrl("https://example.local"))
306-
307-
assert isinstance(exc_info.value.original_error, RuntimeError)
308-
309-
310-
def test_client_config_normalize_base_url_preserves_hyperbrowser_strip_errors():
311-
class _BrokenBaseUrl(str):
312-
def strip(self, chars=None): # type: ignore[override]
313-
_ = chars
314-
raise HyperbrowserError("custom base_url strip failure")
315-
316-
with pytest.raises(
317-
HyperbrowserError, match="custom base_url strip failure"
318-
) as exc_info:
319-
ClientConfig.normalize_base_url(_BrokenBaseUrl("https://example.local"))
320-
321-
assert exc_info.value.original_error is None
322-
323-
324-
def test_client_config_normalize_base_url_wraps_non_string_strip_results():
325-
class _BrokenBaseUrl(str):
326-
def strip(self, chars=None): # type: ignore[override]
327-
_ = chars
328-
return object()
300+
pass
329301

330-
with pytest.raises(HyperbrowserError, match="Failed to normalize base_url") as exc_info:
302+
with pytest.raises(HyperbrowserError, match="base_url must be a string"):
331303
ClientConfig.normalize_base_url(_BrokenBaseUrl("https://example.local"))
332304

333-
assert isinstance(exc_info.value.original_error, TypeError)
334-
335305

336306
def test_client_config_resolve_base_url_from_env_rejects_string_subclass_inputs():
337307
class _BrokenBaseUrl(str):

0 commit comments

Comments
 (0)