def test_overriding_generated_unstructure_hook_func(): """Test overriding a generated unstructure hook works.""" converter = Converter() @attr.define class Inner: a: int @attr.define class Outer: i: Inner inst = Outer(Inner(1)) converter.unstructure(inst) converter.register_unstructure_hook_func( lambda t: t is Inner, lambda _: {"a": 2} ) r = converter.structure(converter.unstructure(inst), Outer) assert r.i.a == 2
def _structure(data: list[dict[str, Any]], cls: Type[LayerSet], converter: GenConverter) -> LayerSet: return cls.from_iterable( converter.structure(layer, Layer) for layer in data)