Skip to content

What should dec_hook raise if the type is unsupported? #774

Closed

Description

@lunik1

Question

There seems to be a (deliberate?) inconsistency in the docs regarding what exception dec_hook should raise if the expected message type is unsupported.

json.decode states that TypeError should be raised.
All other instances state that NotImplementedError should be raised.

Can you clarify which is correct?

  • dec_hook should raise TypeError for unsupported types
  • dec_hook should raise NotImplementedError for unsupported types
  • dec_hook should raise NotImplementedError for unsupported types, unless it is being passed to msgspec.json.decode when it should raise TypeError.
  • other?

Activity

  1. jcrist commented on Nov 20, 2024

    @jcrist
    Member

    Oops, the TypeError there is incorrect (will fix). You should raise a NotImplementedError if the type is unsupported, and raise a TypeError/ValueError if the value doesn't match that type.

  2. added a commit that references this issue on Jul 20, 2026
    593ec54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions