refactor(serply): drop restating comments and type the test helpers

Addresses the Greptile review on #42150: removes the comments that narrate
adjacent code and gives every test helper real parameter and return types
instead of a bare `dict`
This commit is contained in:
serply 2026-09-20 12:36:43 -04:00
parent 972f350fad
commit 755aff801a
No known key found for this signature in database
GPG key ID: 2A6F1A7240DDE6DB
3 changed files with 9 additions and 17 deletions

View file

@ -26,9 +26,6 @@ if TYPE_CHECKING:
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj
_SERPLY_DOCS_URL: Final = "https://serply.io/docs"
# transform_search_request hands the query params to get_complete_url through the
# request body, because Serply is a GET API and the handler only sends the URL.
_PARAMS_KEY: Final = "_serply_params"
@ -120,7 +117,6 @@ class SerplySearchConfig(BaseSearchConfig):
**headers,
"X-Api-Key": resolved_api_key,
"Content-Type": "application/json",
# Serply's client-attribution header: names the calling software, nothing else.
"User-Agent": "litellm",
}
@ -172,8 +168,6 @@ class SerplySearchConfig(BaseSearchConfig):
unified_params: Final = self.get_supported_perplexity_optional_params()
country: Final = optional_params.get("country")
# Spread after the derived values so an explicitly supplied `q`, `num` or `gl` wins
# over anything read out of the unified params.
passthrough: Final = MappingProxyType(
{param: value for param, value in optional_params.items() if param not in unified_params}
)

View file

@ -39,7 +39,7 @@ MOCK_SERPLY_RESPONSE = {
}
def _mock_response():
def _mock_response() -> Mock:
response = Mock()
response.status_code = 200
response.headers = {}
@ -48,7 +48,7 @@ def _mock_response():
return response
def _query_params(mock_get) -> dict:
def _query_params(mock_get: Mock) -> dict[str, list[str]]:
return parse_qs(urlsplit(mock_get.call_args.kwargs["url"]).query)
@ -92,7 +92,6 @@ class TestSerplySearchTransformation:
assert call_kwargs["headers"]["X-Api-Key"] == "test-api-key"
assert call_kwargs["headers"]["User-Agent"] == "litellm"
# Serply is a GET API, so the request is carried entirely by the URL.
assert urlsplit(call_kwargs["url"])._replace(query="").geturl() == "https://api.serply.io/v1/search"
params = _query_params(mock_get)
assert params["q"] == ["(serply search api) (site:serply.io) -site:spam.example"]
@ -105,7 +104,6 @@ class TestSerplySearchTransformation:
assert response.results[0].url == "https://serply.io/"
assert response.results[0].snippet == "Google SERP results as JSON"
assert response.results[0].date == "Aug 11, 2026"
# Second result carries no published_time, so there is no date to report.
assert response.results[1].date is None
def test_provider_specific_params_survive_to_the_wire(self):

View file

@ -11,7 +11,7 @@ def _config() -> SerplySearchConfig:
return SerplySearchConfig()
def _resp(payload, status_code: int = 200):
def _resp(payload: object, status_code: int = 200) -> Mock:
r = Mock()
r.status_code = status_code
r.headers = {}
@ -19,8 +19,8 @@ def _resp(payload, status_code: int = 200):
return r
def _result(**overrides):
base = {
def _result(**overrides: object) -> dict[str, object]:
base: dict[str, object] = {
"title": "Test Title",
"link": "https://example.com",
"description": "Test description",
@ -32,7 +32,7 @@ def _result(**overrides):
return {**base, **overrides}
def _params(query, optional_params=None):
def _params(query: str | list[str], optional_params: dict[str, object] | None = None) -> dict[str, list[str]]:
"""The query string transform_search_request + get_complete_url actually produce."""
config = _config()
data = config.transform_search_request(query, optional_params or {})
@ -108,7 +108,7 @@ def test_get_complete_url_encodes_the_transformed_params():
@pytest.mark.parametrize("data", [None, {}, {"q": "not-wrapped"}, [{"_serply_params": {"q": "x"}}]])
def test_get_complete_url_without_usable_params_returns_a_bare_endpoint(data):
def test_get_complete_url_without_usable_params_returns_a_bare_endpoint(data: object):
"""A malformed body must not produce a URL with a stray query string."""
assert _config().get_complete_url(None, {}, data=data) == "https://api.serply.io/v1/search"
@ -171,7 +171,7 @@ def test_transform_search_request_mixes_include_and_exclude_domains():
@pytest.mark.parametrize("domains", ["arxiv.org", [], ["-"], 7, None])
def test_transform_search_request_leaves_query_alone_for_unusable_domain_filter(domains):
def test_transform_search_request_leaves_query_alone_for_unusable_domain_filter(domains: object):
"""The filter only ever narrows an otherwise valid search, so it must not raise."""
assert _params("q", {"search_domain_filter": domains})["q"] == ["q"]
@ -194,7 +194,7 @@ def test_transform_search_response_reads_published_time(published_time: str):
@pytest.mark.parametrize("metadata", [{}, "not-a-dict", None])
def test_transform_search_response_date_is_none_without_published_time(metadata):
def test_transform_search_response_date_is_none_without_published_time(metadata: object):
resp = _config().transform_search_response(_resp({"results": [_result(metadata=metadata)]}), logging_obj=Mock())
assert resp.results[0].date is None