Skip to content

Promote typing aliases and UseClientDefault to the public API#956

Open
Kludex wants to merge 4 commits into
mainfrom
promote-public-type-aliases
Open

Promote typing aliases and UseClientDefault to the public API#956
Kludex wants to merge 4 commits into
mainfrom
promote-public-type-aliases

Conversation

@Kludex
Copy link
Copy Markdown
Member

@Kludex Kludex commented May 17, 2026

Summary

Downstream libraries (Starlette TestClient, FastAPI, RESPX, pytest-httpx, VCR, HTTPX-based SDKs) currently reach into httpx2._types and httpx2._client to type their wrappers around httpx2.Client / httpx2.AsyncClient:

from httpx2._types import URLTypes, RequestContent, HeaderTypes, ...
from httpx2._client import UseClientDefault, USE_CLIENT_DEFAULT

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 httpx2 namespace.

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-exports UseClientDefault (the class) alongside the already-public USE_CLIENT_DEFAULT sentinel, so callers can annotate parameters as bool | UseClientDefault.
  • httpx2.__all__ is extended accordingly.
  • The setattr(..., "__module__", "httpx2") loop in httpx2/__init__.py now tolerates AttributeError / TypeError, since typing.Union / Optional aliases don't accept __module__ assignment.
  • CHANGELOG entry under Unreleased.

Non-goals

  • No runtime behaviour change; this is API surface only.
  • A formal deprecation policy for these aliases, a documented BaseTransport / AsyncBaseTransport contract, and a separate httpx-protocol types package are intentionally left for follow-up discussion.

Test plan

  • scripts/check (ruff format, ruff check, mypy, unasync) passes
  • tests/httpx2 suite passes (1419 passed, 1 skipped)
  • tests/httpx2/test_exported_members.py still passes (asserts __all__ matches module contents, sorted)
  • Coverage of touched files (__init__.py, _types.py, _client.py) stays at 100%
  • Manual smoke: httpx2.URLTypes, httpx2.UseClientDefault, etc. all resolve and isinstance(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.

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.
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 17, 2026

Merging this PR will not alter performance

✅ 7 untouched benchmarks


Comparing promote-public-type-aliases (b399671) with main (8d5f182)

Open in CodSpeed

Kludex added 3 commits May 17, 2026 07:02
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.
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

Successfully merging this pull request may close these issues.

1 participant