I think it might be a better design choice to have the HTTP client encapsulated within the PyPIServices class, and for it to configure it however it needs. The code itself will also look cleaner:
|
if package_version is not None: |
|
url = f"https://pypi.org/pypi/{package_title}/{package_version}/json" |
|
else: |
|
url = f"https://pypi.org/pypi/{package_title}/json" |
The duplicated base URLs can be extracted into the configuration for the HTTP client.
With regard to testing, perhaps you could accept a HTTP client factory method rather than accepting the object directly instead. The default factory would be httpx.Client/httpx.AsyncClient, and tests can pass in a mock that would override it to whatever else.
I think it might be a better design choice to have the HTTP client encapsulated within the
PyPIServicesclass, and for it to configure it however it needs. The code itself will also look cleaner:letsbuilda-pypi/src/letsbuilda/pypi/sync_client.py
Lines 34 to 37 in 8b02f30
The duplicated base URLs can be extracted into the configuration for the HTTP client.
With regard to testing, perhaps you could accept a HTTP client factory method rather than accepting the object directly instead. The default factory would be
httpx.Client/httpx.AsyncClient, and tests can pass in a mock that would override it to whatever else.