Exemplo n.º 1
0
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
Exemplo n.º 2
0
 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)