Skip to content

feat(story-1.5): ResponseDecoder protocol and pydantic adapter#5

Merged
lesnik512 merged 1 commit into
mainfrom
story/1-5-responsedecoder-protocol-and-pydantic-adapter
May 31, 2026
Merged

feat(story-1.5): ResponseDecoder protocol and pydantic adapter#5
lesnik512 merged 1 commit into
mainfrom
story/1-5-responsedecoder-protocol-and-pydantic-adapter

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Summary

  • Introduces the AsyncClient ↔ ResponseDecoder seam (Seam 3): ResponseDecoder runtime-checkable Protocol and PydanticDecoder adapter built on pydantic.TypeAdapter.validate_json(bytes) for a single-parse-pass.
  • A module-level lru_cache(maxsize=1024) factory memoizes one TypeAdapter per response_model across the process; the benchmark shows ~1.58× speedup vs. a two-pass json.loads + validate_python baseline.
  • Adds the perf pytest marker (skipped by default; opt-in via pytest -m perf) and the matching test file for the single-pass vs two-pass comparison.
  • Records four code-review deferrals to docs/deferred-work.md and exports ResponseDecoder + PydanticDecoder from 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.
  • CI green on all matrix entries.

🤖 Generated with Claude Code

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>
@lesnik512 lesnik512 self-assigned this May 31, 2026
@lesnik512 lesnik512 merged commit f9e03ab into main May 31, 2026
5 checks passed
@lesnik512 lesnik512 deleted the story/1-5-responsedecoder-protocol-and-pydantic-adapter branch May 31, 2026 10:11
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