[docs]classStructurer:def__init__(self,lookup_handlers:Mapping[Any,Callable[["Structurer",type,Any],Any]]={},sequential_handlers:Iterable[SequentialStructureHandler]=[],):self._lookup_handlers=lookup_handlersself._sequential_handlers=sequential_handlers@overloaddefstructure_into(self,structure_into:NewType,val:Any)->Any:...@overloaddefstructure_into(self,structure_into:type[_T],val:Any)->_T:...defstructure_into(self,structure_into:Any,val:Any)->Any:stack=GeneratorStack((self,structure_into),val)lookup_order=get_lookup_order(structure_into)fortpinlookup_order:handler=self._lookup_handlers.get(tp,None)ifstack.push(handler):returnstack.result()# Check all sequential handlers in order and see if there is one that applies# TODO (#10): should `applies()` raise an exception which we could collect# and attach to the error below, to provide more context on why no handlers were found?forsequential_handlerinself._sequential_handlers:ifsequential_handler.applies(structure_into,val):ifstack.push(sequential_handler):returnstack.result()breakifstack.is_empty():raiseStructuringError(f"No handlers registered to structure into {structure_into}")raiseStructuringError(f"Could not find a non-generator handler to structure into {structure_into}")