feat(story-1.5): ResponseDecoder protocol and pydantic adapter#5
Merged
lesnik512 merged 1 commit intoMay 31, 2026
Merged
Conversation
Introduces the AsyncClient ↔ ResponseDecoder seam (Seam 3): - `ResponseDecoder` runtime-checkable Protocol with `decode(content, model)`. - `PydanticDecoder` adapter using `pydantic.TypeAdapter.validate_json(bytes)` for a single-parse-pass; a module-level `lru_cache` factory memoizes one `TypeAdapter` per `response_model` across the process. - Public exports: `ResponseDecoder`, `PydanticDecoder`. - Performance tests gated behind `-m perf` (skipped by default; opt-in via `pytest -m perf`) with a `perf` marker registered in `pyproject.toml`. - Code-review deferrals for empty/malformed payloads, PLR2004 per-file-ignore consolidation, CHANGELOG tone, and runtime_checkable isinstance cost recorded in docs/deferred-work.md. - README adds the modern-python org pointer. Sprint status: 1-5 → done; epic-1 still in-progress (1-6, 1-7, 1-8 remain). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
5 tasks
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
AsyncClient ↔ ResponseDecoderseam (Seam 3):ResponseDecoderruntime-checkable Protocol andPydanticDecoderadapter built onpydantic.TypeAdapter.validate_json(bytes)for a single-parse-pass.lru_cache(maxsize=1024)factory memoizes oneTypeAdapterperresponse_modelacross the process; the benchmark shows ~1.58× speedup vs. a two-passjson.loads+validate_pythonbaseline.perfpytest marker (skipped by default; opt-in viapytest -m perf) and the matching test file for the single-pass vs two-pass comparison.docs/deferred-work.mdand exportsResponseDecoder+PydanticDecoderfrom the package root.Test plan
uv run pytest -q— 157 passed, 1 deselected (the perf bench), 100% line coverage.uv run ruff check .— clean.uv run ty check— clean.uv run pytest -m perf— benchmark runs; single-pass adapter beats two-pass baseline.🤖 Generated with Claude Code