Promote typing aliases and UseClientDefault to the public API#956
Open
Kludex wants to merge 4 commits into
Open
Promote typing aliases and UseClientDefault to the public API#956Kludex wants to merge 4 commits into
UseClientDefault to the public API#956Kludex wants to merge 4 commits into
Conversation
Downstream libraries (Starlette `TestClient`, FastAPI, RESPX, pytest-httpx, ...) currently import these from `httpx2._types` and `httpx2._client`, both private modules with no stability guarantee. Promote the aliases that already exist to the top-level `httpx2` namespace so downstreams can depend on them.
Alphabetical sorting scatters related symbols (`Auth` vs `AuthTypes`, `AsyncClient` vs `AsyncByteStream`). Organize entries by the submodule they come from instead, matching the `from ._foo import *` order at the top of `__init__.py`, with a section comment per group. Relax `test_all_imports_are_exported` to compare sets rather than asserting a specific order, since order is now intentional.
This reverts commit 4a0c152.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Downstream libraries (Starlette
TestClient, FastAPI, RESPX, pytest-httpx, VCR, HTTPX-based SDKs) currently reach intohttpx2._typesandhttpx2._clientto type their wrappers aroundhttpx2.Client/httpx2.AsyncClient:Both modules are underscore-prefixed and carry no stability guarantee, so any rename there is a downstream break. This PR promotes the aliases (which already exist) to the public
httpx2namespace.Changes
httpx2._types.__all__now re-exports the typing aliases:URLTypes,QueryParamTypes,HeaderTypes,CookieTypes,TimeoutTypes,AuthTypes,RequestContent,RequestData,RequestExtensions,RequestFiles,ResponseContent,ResponseExtensions,FileContent,FileTypes,CertTypes,ProxyTypes,PrimitiveData.httpx2._client.__all__now re-exportsUseClientDefault(the class) alongside the already-publicUSE_CLIENT_DEFAULTsentinel, so callers can annotate parameters asbool | UseClientDefault.httpx2.__all__is extended accordingly.setattr(..., "__module__", "httpx2")loop inhttpx2/__init__.pynow toleratesAttributeError/TypeError, sincetyping.Union/Optionalaliases don't accept__module__assignment.Non-goals
BaseTransport/AsyncBaseTransportcontract, and a separatehttpx-protocoltypes package are intentionally left for follow-up discussion.Test plan
scripts/check(ruff format, ruff check, mypy, unasync) passestests/httpx2suite passes (1419 passed, 1 skipped)tests/httpx2/test_exported_members.pystill passes (asserts__all__matches module contents, sorted)__init__.py,_types.py,_client.py) stays at 100%httpx2.URLTypes,httpx2.UseClientDefault, etc. all resolve andisinstance(httpx2.USE_CLIENT_DEFAULT, httpx2.UseClientDefault)holds.AI Disclaimer
This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.