Skip to content

Commit 593ec54

Browse files
authored
Fix dec_hook exception type in json.decode docstring (msgspec#1127)
Fixes msgspec#774. `json.decode` was the only `dec_hook` docstring telling users to raise a `TypeError` for an unsupported type. `json.Decoder`, `msgpack.decode`, `msgpack.Decoder`, and `convert` all say `NotImplementedError`, which is the intended contract you confirmed in msgspec#774 (`TypeError`/`ValueError` are for a value that doesn't match the type). This changes the one line to match. Grepped the rest of the tree for the wording and this docstring was the only copy, so there's nothing to fix in the docs or stubs. Added an `## Unreleased` changelog entry. I pointed it at the issue with `{issue}`774`` since there was no PR number when I wrote it; happy to swap it to `{pr}` with this PR's number. Disclosure: I used AI assistance (Claude) to draft this change and reviewed the result.
1 parent a1ebbcd commit 593ec54

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)