baybe.serialization.core.make_base_structure_hook

baybe.serialization.core.make_base_structure_hook(base: type[_T])[source]

Create a hook for structuring subclasses using annotations of their base class.

Reads the type information from the given input to retrieve the correct subclass and then calls the existing structure hook of the that class.

For generic base classes, this hook preserves the generic type parameters when dispatching to concrete subclasses. For example, if structuring with BaseClass[Type], the concrete subclass will be called as ConcreteClass[Type] rather than just the plain ConcreteClass.