Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create internal httpx client rather than having users pass it in #86

Open
Robin5605 opened this issue Apr 4, 2024 · 0 comments
Open

Comments

@Robin5605
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant