Skip to content

Commit 5f647c4

Browse files
lesnik512claude
andcommitted
fix(story-1.6): drop pydantic fallback in MsgspecDecoder
The spec inherited a wrong assumption from the archived AC: msgspec does NOT decode into pydantic BaseModel subclasses natively (only msgspec.Struct, dataclasses, attrs, NamedTuples, TypedDicts, and builtins). The initial Task 2 implementation worked around this with a hasattr(model, "model_validate_json") fallback, but that muddies MsgspecDecoder's responsibility, defeats the single C-level pass property, and crosses ecosystems. Revert: MsgspecDecoder.decode is now a one-liner that just calls msgspec.json.decode(content, type=model). Pydantic users use PydanticDecoder. The test for pydantic decoding is dropped; the remaining 7 tests cover msgspec.Struct, builtin, list[Struct], ValidationError, DecodeError, protocol satisfaction, and the missing-extra construction path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 37686be commit 5f647c4

2 files changed

Lines changed: 2 additions & 19 deletions

File tree

‎src/httpware/decoders/msgspec.py‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,5 @@ def __init__(self) -> None:
3131
raise ImportError(MISSING_DEPENDENCY_MESSAGE)
3232

3333
def decode(self, content: bytes, model: type[T]) -> T:
34-
"""Validate `content` as JSON against `model` in a single parse pass.
35-
36-
Falls back to `model.model_validate_json` for Pydantic BaseModel types,
37-
since msgspec cannot natively decode into Pydantic models.
38-
"""
39-
if hasattr(model, "model_validate_json"):
40-
return model.model_validate_json(content) # ty: ignore[call-non-callable]
41-
return msgspec.json.decode(content, type=model) # guarded by import_checker above
34+
"""Validate `content` as JSON against `model` in a single parse pass."""
35+
return msgspec.json.decode(content, type=model)

‎tests/test_decoders_msgspec.py‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import msgspec
44
import pytest
5-
from pydantic import BaseModel
65

76
from httpware._internal import import_checker
87
from httpware.decoders import ResponseDecoder
@@ -14,11 +13,6 @@ class _Item(msgspec.Struct):
1413
qty: int
1514

1615

17-
class _ItemModel(BaseModel):
18-
name: str
19-
qty: int
20-
21-
2216
def test_decoder_satisfies_response_decoder_protocol() -> None:
2317
assert isinstance(MsgspecDecoder(), ResponseDecoder)
2418

@@ -28,11 +22,6 @@ def test_decode_into_msgspec_struct() -> None:
2822
assert result == _Item(name="x", qty=1)
2923

3024

31-
def test_decode_into_pydantic_model() -> None:
32-
result = MsgspecDecoder().decode(b'{"name":"y","qty":2}', _ItemModel)
33-
assert result == _ItemModel(name="y", qty=2)
34-
35-
3625
def test_decode_into_builtin_type() -> None:
3726
result = MsgspecDecoder().decode(b"42", int)
3827
assert result == 42 # noqa: PLR2004

0 commit comments

Comments
 (0)