Skip to content

Commit dcf6a65

Browse files
committed
Fix dec_hook exception type in json.decode docstring
Fixes #774. json.decode was the only dec_hook docstring saying to raise a TypeError for an unsupported type; json.Decoder, msgpack.decode, msgpack.Decoder, and convert all say NotImplementedError, which jcrist confirmed in #774 is the intended contract (TypeError/ValueError are for bad values). The changelog entry points at the issue since there's no PR number yet; it can reference the PR instead once one exists. Disclosure: I used AI assistance (Claude) to draft this change and reviewed the result.
1 parent a1ebbcd commit dcf6a65

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

‎docs/changelog.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
`msgspec.to_builtins` ({pr}`1025`).
2828
- Document that `omit_defaults` ignores fields with a custom
2929
`default_factory` ({pr}`1076`).
30+
- Fix the `msgspec.json.decode` docstring to say `dec_hook` should raise
31+
`NotImplementedError` for unsupported types, not `TypeError` ({issue}`774`).
3032
- msgspec moved to the [msgspec GitHub organization](https://github.com/msgspec/msgspec);
3133
documentation now lives at [msgspec.dev](https://msgspec.dev) (repository
3234
references updated in {pr}`1045`).

‎src/msgspec/_core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19945,7 +19945,7 @@ PyDoc_STRVAR(msgspec_json_decode__doc__,
1994519945
" signature ``dec_hook(type: Type, obj: Any) -> Any``, where ``type`` is the\n"
1994619946
" expected message type, and ``obj`` is the decoded representation composed\n"
1994719947
" of only basic JSON types. This hook should transform ``obj`` into type\n"
19948-
" ``type``, or raise a ``TypeError`` if unsupported.\n"
19948+
" ``type``, or raise a ``NotImplementedError`` if unsupported.\n"
1994919949
"\n"
1995019950
"Returns\n"
1995119951
"-------\n"

0 commit comments

Comments
 (0)