refactor(client): extract shared request-assembly functions#98
Merged
Conversation
Extract 3 pure, non-I/O logic blocks from Client/AsyncClient into module-level functions to eliminate hand-copied duplication: - _validate_httpx2_client_conflict: constructor-conflict validation - _assemble_httpx2_client_kwargs: constructor kwargs-dict assembly - _assemble_request_kwargs: per-request kwargs-dict assembly (used in _prepare_request and stream, both sync and async) This is a pure internal refactor with no behavior change. All 775 existing tests pass at 100% coverage. Added test_request_assembly.py covering all edge cases (empty dicts, full dicts, falsy-string handling, timeout semantics difference between client and per-request calls). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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
__init__/_prepare_request/stream()bodies inclient.py:_validate_httpx2_client_conflict,_assemble_httpx2_client_kwargs,_assemble_request_kwargs(the last reused across 4 call sites — both_prepare_requests and bothstream()s).client.py(not moved to_internal/) and as plain functions (not a class), per the_CircuitBreakerState/_RetryPolicyprecedent already in this codebase._request_with_body/_terminal, and any I/O call sites — the async/await split there is structural, and codegen (unasync-style) was considered and rejected. See the design for the full rationale.Design:
planning/changes/2026-07-13.02-client-request-assembly-extraction.mdTest plan
just test— 775 passed, 100% coveragejust lint-ci— ruff format/check,ty check, planning validator all clean