Internalize http client management, add context manager support #15
No reviewers
Labels
No labels
bug
contribution welcome
duplicate
enhancement
good first issue
help wanted
invalid
question
upstream
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Reference
marvin8/longwei!15
Loading…
Reference in a new issue
No description provided.
Delete branch "refs/pull/15/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Removes httpx.AsyncClient from the public API. APClient now creates and owns its own client internally.
Changes:
Closes #6
Closes #14
Also replacing httpx with httpx2
As part of this branch we are also migrating from httpx to httpx2 (https://httpx2.pydantic.dev) — Pydantic's actively maintained fork of httpx. This resolves the zstd dependency that currently blocks Python 3.15 testing (see #6).
What httpx2 is
httpx2 is a drop-in replacement for httpx at the API level: same class names (
AsyncClient,HTTPError,Response, etc.), same exceptions, same request/response interface. The migration is transparent to longwei consumers — nothing changes in the public API.What the migration involved
Source files (8 files): Mechanical import swap —
from httpx import X→from httpx2 import X. No logic changes.Test infrastructure (all ~50 test files): This was the significant part.
pytest-httpxpatcheshttpcoreat the transport level. httpx2 useshttpcore2(a separate package), sopytest-httpxcannot intercept httpx2 requests. The replacement ispytest-httpx2, which provides ahttpx2_mockfixture backed byrespx. The respx API is completely different from the pytest-httpxHTTPXMockAPI:httpx_mock.add_response(json=X, headers=Y)httpx2_mock.route().respond(json=X, headers=Y)httpx_mock.add_response(status_code=N)httpx2_mock.route().respond(N)httpx_mock.add_exception(HTTPError(...))httpx2_mock.route().mock(side_effect=HTTPError(...))httpx_mock.get_request()httpx2_mock.calls.last.requesthttpx_mock.get_requests()[0]httpx2_mock.calls[0].request@pytest.mark.httpx_mock(assert_all_responses_were_requested=False)add_response(url="...", ...)httpx2_mock.get("...").respond(...)All test files were converted systematically using this mapping.
Python 3.15 beta testing
The
pytest_betasnox session (which runs the test suite against Python 3.15 and 3.15t) currently fails becausepydantic-core 2.41.5depends onpyo3 0.26.0, which declares Python 3.14 as its maximum supported version.The failure is not a Rust tooling problem — even with Rust installed, the build aborts with:
This is a pydantic-side issue. Once pydantic-core ships a release built against pyo3 ≥ 0.27 (which will add 3.15 support), pre-built wheels will appear on PyPI and the failure will resolve automatically — no changes needed on our end.
The CI pipeline has been updated in this branch to run
nox -s pytest_betasas a separate step withfailure: ignore, so it runs and reports results without blocking the build.