Skip to content

refactor(client): extract shared request-assembly functions#98

Merged
lesnik512 merged 2 commits into
mainfrom
worktree-client-request-assembly-extraction
Jul 13, 2026
Merged

refactor(client): extract shared request-assembly functions#98
lesnik512 merged 2 commits into
mainfrom
worktree-client-request-assembly-extraction

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Summary

  • Extracts 3 shared, non-I/O helper functions out of Client/AsyncClient's hand-duplicated __init__/_prepare_request/stream() bodies in client.py: _validate_httpx2_client_conflict, _assemble_httpx2_client_kwargs, _assemble_request_kwargs (the last reused across 4 call sites — both _prepare_requests and both stream()s).
  • Kept inside client.py (not moved to _internal/) and as plain functions (not a class), per the _CircuitBreakerState/_RetryPolicy precedent already in this codebase.
  • Deliberately out of scope: the per-verb methods, _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.md

Test plan

  • just test — 775 passed, 100% coverage
  • just lint-ci — ruff format/check, ty check, planning validator all clean
  • Task-scoped review (spec + quality): Approved
  • Final whole-branch review: Ready to merge = Yes, no Critical/Important findings

lesnik512 and others added 2 commits July 13, 2026 14:06
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>
@lesnik512 lesnik512 merged commit 7705fc8 into main Jul 13, 2026
6 checks passed
@lesnik512 lesnik512 deleted the worktree-client-request-assembly-extraction branch July 13, 2026 11:38
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